与NEST ElasticSearch库的连接池

Chr*_*ase 4 c# connection-pooling elasticsearch nest

我目前正在使用NEST ElasticSearch C#Library与ElasticSearch进行交互.我的项目是一个MVC 4 WebAPI项目,它基本上构建了一个RESTful Web服务来访问目录服务信息.

我们刚刚开始与NEST合作,并且一直在为缺乏文档而磕磕绊绊.什么是有用的,但它有一些非常大的漏洞.目前,我们需要的一切工作,但是,我们遇到的问题是连接有时需要一整秒.我们想要做的是使用某种连接池,类似于您与SQL Server交互的方式.

以下是有关如何使用nest连接的文档:http://mpdreamz.github.com/NEST/concepts/connecting.html

以下是我们项目的相关代码段:

public class EOCategoryProvider : IProvider
{
    public DNList ExecuteQuery(Query query)
    {
        //Configure the elastic client and it's settings
        ConnectionSettings elasticSettings = new ConnectionSettings(Config.server, Config.port).SetDefaultIndex(Config.index);
        ElasticClient client = new ElasticClient(elasticSettings);

        //Connect to Elastic
        ConnectionStatus connectionStatus;
        if (client.TryConnect(out connectionStatus))
        {
            // Elastic Search Code here ...
        } // end if
    } // end ExecuteQuery
} // end EOCategoryProvider
Run Code Online (Sandbox Code Playgroud)

从查看文档,我看不到连接池的任何规定.我一直在考虑实现我自己的(有3个或4个ElasticClient对象存储,并选择它们循环风格),但我想知道是否有人有更好的解决方案.如果没有,有没有人有关于手动实现连接池的最佳方法的建议?有什么文章指向?

感谢你们提出的任何事情.

更新:这似乎与在每个请求和特定网络设置上调用TryConnect有关.当在与弹性盒子相同的网络上使用机器时,问题完全消失了; 我的开发机器(平均350毫秒到弹性盒子)似乎有时无法建立http连接,这导致了TryConnect的长时间.

Mar*_*man 19

你不必打电话给TryConnect()每一个你做Elasticsearch通话时间.它基本上是一个完整的应用程序启动时的健全检查调用.

NEST是Elasticsearch C#的REST客户端,默认IConnection使用WebRequest.Create其已经池中的TCP连接.

查看实际实现:https://github.com/elastic/elasticsearch-net/blob/master/src/Elasticsearch.Net/Connection/HttpConnection.cs

重复使用ElasticClient不会提供任何性能提升,因为每个呼叫已经有了自己的 HttpWebRequest.整个客户都是故意无国籍的.

然而,我对你为什么打电话需要1秒钟非常感兴趣.您是否可以发布实际的NEST代码,如何测量呼叫并描述您的数据.

免责声明:我是NEST的作者.