简体   繁体   English

使用NEST获取ElasticSearch批量队列状态

[英]Get ElasticSearch bulk queue status with NEST

I have a program that performs several bulk index operation on an ElasticSearch cluster. 我有一个程序,在ElasticSearch集群上执行多个批量索引操作。 At some point, I start getting errors like this one (snipped): 在某个时候,我开始收到像这样的错误(已删除):

RemoteTransportException[...][indices:data/write/bulk[s]]]; nested: EsRejectedExecutionException[rejected execution (queue capacity 100) ...];

Is there a way I can verify the status of the bulk upload queue, ideally using NEST, so that I can slow down the client application in case I see that the queue on the server is getting full? 有没有一种方法可以验证批量上传队列的状态(理想情况下使用NEST),以便在看到服务器上的队列已满时可以减慢客户端应用程序的速度?

The NodesInfo method looks interesting, but I don't see how to access the information I need: NodesInfo方法看起来很有趣,但是我看不到如何访问所需的信息:

using Nest;
using System;

class Program {
    static void Main(string[] args) {
        ElasticClient client = new ElasticClient(new ConnectionSettings(new Uri("http://whatever:9200/")));
        var nodesInfoResponse = client.NodesInfo();
        if (nodesInfoResponse.IsValid) {
            foreach (var n in nodesInfoResponse.Nodes) {
                Console.WriteLine($"Node: {n.Key}");
                var bulk = n.Value.ThreadPool["bulk"];
                // ???
            }
        }
    }
}

You need to use NodesStats() and not NodesInfo() . 您需要使用NodesStats()而不是NodesInfo()

var nodesStatsResponse = client.NodesStats();
if (nodesStatsResponse.IsValid)
{
    foreach (var node in nodesStatsResponse.Nodes)
    {
        long bulkThreadPoolQueueSize = node.Value.ThreadPool["bulk"].Queue;
    }
}

UPDATE: The above query will bring in a lot of information than required. 更新:上面的查询将带来很多信息,而不是所需的信息。 A highly optimized request for getting the same information is through the usage of _cat/thread_pool API. 为获得相同信息而进行的高度优化的请求是通过使用_cat/thread_pool API。 See below: 见下文:

var catThreadPoolResponse = client.CatThreadPool(d => d.H("host", "bulk.queue"));
if (catThreadPoolResponse.IsValid)
{
    foreach (var record in catThreadPoolResponse.Records)
    {
        string nodeName = record.Host;
        long bulkThreadPoolQueueSize = int.Parse(record.Bulk.Queue);
        Console.WriteLine($"Node [{nodeName}] : BulkThreadPoolQueueSize [{bulkThreadPoolQueueSize}]");
    }
}

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

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