简体   繁体   English

ElasticSearch Nest 2.x-性能问题,如何禁用审核跟踪?

[英]ElasticSearch Nest 2.x - Performance issue, how to disable audit trail?

I'm running search queries using Elasticsearch client NEST 2. Queries are running fine but inspecting the response I can see that a huge time is spent auditing the query while the ES operation itself is done in a snap. 我正在使用Elasticsearch Client NEST 2运行搜索查询。查询运行良好,但是检查响应我可以看到,在ES操作本身快速完成的同时,审计查询花费了大量时间。

Here is an example of a request/response : 这是一个请求/响应的示例:

Succesful low level call on POST: /document/ElasticDocument/_search 在POST上成功进行低级调用:/ document / ElasticDocument / _search

Audit trail of this API call: - HealthyResponse: Node: http://my-ES-server.com:9200/ Took: 00:00:00.3040912 此API调用的审核跟踪:-HealthyResponse:节点: http ://my-ES-server.com:9200/接收时间:00:00:00.3040912
Request: {"from":0,"size":1,"query":{"term":{"Id":{"value":1568}}}} 请求:{“ from”:0,“ size”:1,“ query”:{“ term”:{“ Id”:{“ value”:1568}}}}
Response: { "took":16 ,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":9.345218,"hits":[{"_index":"document","_type":"ElasticDocument","_id":"1568","_score":9.345218,"_source":{........}}]}} 响应:{ “ took”:16 ,“ timed_out”:false,“ _ shards”:{“ total”:5,“ successful”:5,“ failed”:0},“ hits”:{“ total”:1, “MAX_SCORE”:9.345218, “点击”:[{ “_指数”: “文件”, “_类型”: “ElasticDocument”, “_ ID”: “1568”, “_分数”:9.345218, “_源”:{... .....}}]}}

We can see that the audit took 304ms while the ES search took only 16. 我们可以看到,审核花费了304毫秒,而ES搜索仅花费了16毫秒。

My question is, is there anyway to disable this audit trail or tweak the configuration to effectively improve the performance ? 我的问题是,是否仍要禁用此审计跟踪或调整配置以有效地提高性能?

I had a look at the source code and found out that the audit trail operation is triggered by the ElasticsearchResponse's property DebugInformation but couldn't find how to disable it. 我查看了源代码,发现审计跟踪操作是由ElasticsearchResponse的属性DebugInformation触发的,但是找不到如何禁用它。

My configuration is pretty straight forward : 我的配置非常简单:

var node = new Uri("http://my-ES-server.com:9200/");

var settings = new ConnectionSettings(node);

settings.DefaultIndex("document");
settings.DefaultTypeNameInferrer(p => p.Name);
settings.DefaultFieldNameInferrer(p => p);

settings.DisableDirectStreaming(); 

this.elasticClient = new ElasticClient(settings);

And then my nest call : 然后我的嵌套调用:

var response = this.elasticClient.Search<ElasticDocument>(s => s
    .Query(q => q.Term("Id", documentId))
    .From(0)
    .Take(1)
);

For information, when I'm running the queries against a local ES store (populated with same data) audit trail takes ~60ms which is better but still huge comparing to the ES search operation. 有关信息,当我针对本地ES商店(填充相同数据)运行查询时,审计跟踪大约需要60毫秒,这比ES搜索操作更好,但仍然很大。

Many thanks, 非常感谢,

Mickael 迈克尔

Audit Trail information is built when the .DebugInformation property is accessed . 访问.DebugInformation属性时,将构建审核跟踪信息

took in the response is the time taken on the cluster for Elasticsearch to execute the search and doesn't include took响应是Elasticsearch在集群上执行搜索所花费的时间并且不包括

  1. time to serialize the request 时间序列化请求
  2. network latency going to the selected Elasticsearch node 到达所选Elasticsearch节点的网络延迟
  3. network latency coming back from the selected Elasticsearch node 来自选定的Elasticsearch节点的网络延迟
  4. time to deserialize the response 时间反序列化响应

Contrastly, the Took time that you see in the audit trail is a rough (in the sense it is calculated with an IDateTimeProvider implementation that uses DateTime precision by default) total time between Contrastly中, Took你在审计跟踪中看到的时间是一个粗略的 (在它与计算感IDateTimeProvider使用实施DateTime默认精度) 之间的总时间

  1. getting a node from the IConnectionPool IConnectionPool获取节点
  2. serializing the request 序列化请求
  3. sending the request to the node 发送请求到节点
  4. time take on the Elasticsearch node Elasticsearch节点上花费的时间
  5. receiving the response back from the node 从节点接收回响应
  6. deserializing the response 反序列化响应

Because of differences in network latency, the number reported in the audit trail could vary in different environments. 由于网络延迟的差异,审核跟踪中报告的数量在不同的环境中可能会有所不同。 Further, it's likely to be higher on the first request because of the initialization of caches used for member access by the json serializer. 此外,由于json序列化程序用于成员访问的缓存的初始化,因此在第一个请求上它可能更高。

As an aside, looking at your configuration, unless you need to access the request or response body bytes, do not call .DisableDirectStreaming() ; .DisableDirectStreaming() ,查看您的配置,除非您需要访问请求或响应主体字节, 否则不要调用.DisableDirectStreaming() ; this copies the request and response to a MemoryStream internally in order to make the bytes available. 这会将请求和响应内部复制到MemoryStream以便使字节可用。

I had similar problem and it is not about Audit trail. 我有类似的问题,这与审核跟踪无关。 The point is that NEST uses by default Accept: application/json header. 关键是NEST默认使用Accept: application/json标头。 When you set EnableHttpCompression() on your client, NEST starts to use Accept-Encoding: gzip, deflate header and that's correct. 当您在客户端上设置EnableHttpCompression()时,NEST开始使用Accept-Encoding: gzip, deflate标头,这是正确的。

This is my client initialization code: 这是我的客户端初始化代码:

var node = new Uri("http://localhost.:9200");
var settings = new ConnectionSettings(node)
    .EnableHttpCompression()
    .PrettyJson();
var client = new ElasticClient(settings);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM