문제

우리는 Solr/Solr.net에서 Elasticsearch로 전환하는 것을 고려하고 있습니다.우리는 시작했다 둥지.검색 색인에는 문서가 4개만 있습니다.

private static void Main(string[] args)
{
    var node = new Uri("http://localhost:9200");
    var settings = new ConnectionSettings(
        node, "my-application");

    var client = new ElasticClient(settings);

    var stopwatch = Stopwatch.StartNew();
    var sr = client.Get<Movie>(1);

    Console.WriteLine(stopwatch.ElapsedMilliseconds);
}

위의 코드는 대략 소요됩니다.250ms, 동일한 코드는 HttpClient 그리고 JsonSerializer 30-45ms가 걸립니다.250ms는 단 4개의 문서에 너무 많은 시간입니다.

트래픽이 많은 뉴스 웹사이트에서 NEST를 사용할 수 있나요? 아니면 추천하시나요? HttpClient + JsonSerializer 콤보?검색 페이지는 2013년 당사 웹사이트에서 가장 많이 방문한 페이지였습니다.

미리 감사드립니다.

도움이 되었습니까?

해결책

NEST가 첫 번째 요청을 하기 위해서는 두 가지 일이 일어나야 합니다.

  1. 이 경우 Json Serializer(Json.net)는 주고받는 개체를 직렬화 및 역직렬화하는 방법을 알 수 있도록 유형을 캐시해야 합니다.

  2. Nest에는 유창한 쿼리 언어를 나타내는 초기 유형을 변환하고 탄력적 검색에 JSON으로 전달해야 하는 쿼리에 대한 고유한 유창한 언어가 있습니다.이러한 문서 유형은 Json Serializer에서도 학습되어야 합니다.

  3. 요청을 하려면 HTTP 클라이언트를 가동해야 합니다.

현재 NEST와 함께 사용하는 단일 인덱스에 400만 개 이상의 문서가 있으며 인터넷을 통해 서버에서 클라이언트까지 검색하는 데 NEST를 사용하면 50-70ms가 걸립니다.그러나 여러분과 마찬가지로 콜드 스타트 ​​후 첫 번째 요청은 느립니다.

다른 팁

나는 당신이 사용하는 것이 좋습니다 https://github.com/ServiceStack/ServiceStack.Text, C#에 대한 가장 빠른 JSON 시리얼 라이저.

운전자의 경우 낮은 수준의 것을 사용하고, http://nest.azurewebsites.net/elasticsearch-net/quick-start.html

코드 아래에 내 앱을 자세히 기록하고 분석하기 위해 작성하기 시작했습니다.아직 일을 해야 하지만 좋은 시작이 될 수 있습니다.

using System;
using System.Configuration;
using Elasticsearch.Net;
using Elasticsearch;
using Elasticsearch.Net.Connection;
using Elasticsearch.Net.ConnectionPool;

namespace Common {

    /// <summary>
    /// Elastic search. Singletone, open connection and thread safe to be open for all the time
    /// the app is running, so we send ours logs to ealsticsearch to be analyzed, assychronly
    /// See the fourth version;
    /// http://csharpindepth.com/articles/general/singleton.aspx
    /// </summary>
    public sealed class ElasticSearch {
        // our instance of ourself as a singleton
        private static readonly ElasticSearch instance = new ElasticSearch();

        ElasticsearchClient client;
        string connectionString = ConfigurationManager.ConnectionStrings["Elasticsearch"].ConnectionString;

        /// <summary>
        /// Initializes a new instance of the <see cref="Common.ElasticSearch"/> class.
        /// Follow this: http://nest.azurewebsites.net/elasticsearch-net/connecting.html
        /// We use a ConnectionPool to make the connection fail-over, that means, if the 
        /// connection breaks, it reconnects automatically
        /// </summary>
        private ElasticSearch() {
            var node = new Uri(connectionString);
            var connectionPool = new SniffingConnectionPool(new[] { node });
            var config = new ConnectionConfiguration(connectionPool);
            client = new ElasticsearchClient(config);   // exposed in this class
        }

        static ElasticSearch() {
        }

        /// <summary>
        /// Gets the instance of our singleton class
        /// </summary>
        /// <value>The instance.</value>
        public static ElasticSearch Instance {
            get {
                return instance;
            }
        }

        /// <summary>
        /// Log the specified module, id and json.
        /// </summary>
        /// <param name="type">Here the entity you want to save your log,
        /// let's use it based on classes and StateMachines</param>
        /// <param name="id">Identifier. alwayes the next</param>
        /// <param name="json">Json.</param>
        public void Log(string type, string id, string json) {
            client.Index("mta_log", type, id, json);
        }

    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top