Reputation: 1010
When using the .NET Elasticsearch NEST client, I'm trying to figure out how to minimize the number of pings the client library does to our nodes. I know there are settings to disable the pings, but if we had a node down I think we would see a big negative performance impact without them. So what I'm really trying to figure out is if there is a way to use a singleton pattern around the ElasticClient object, connection state information or some other object to help achieve this.
Basically we need a shared object that has all the nodes and their up/down state that multiple ElasticClients can use without having each new client created having to figure it out. Another option would be using the ElasticClient as a singleton itself.
I am using the client in a multithreaded ASP.NET app and azure worker role so ensuring it works across threads is important.
I'm using nginx in front of ES to monitor it's traffic and you can see there are a ton of "/" hits which must be the client library pings. (This report snippet below is via Stackify from parsing our nginx logs.)
Has anyone had any success using ElasticClient as a singleton or have any suggestions?
Upvotes: 0
Views: 1937
Reputation: 13536
The client itself is stateless so you should be able to use it as a singleton. You can also instantiate a new client every time but if your using an IConnectionPool
you need to make sure each of the client instances receives the same instance of the IConnectionPool
.
Upvotes: 2