Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Search Transport Client. Singleton vs One new instance for each call vs Connection Pool (if any)

I am connecting to elastic search using Elastic Search Transport Client. There are two approaches that I've tried

1) Singleton client shared across my entire application. Time to response is between 1-2s

2) New client instance for every call to Elastic Search, takes about 7s to respond. To be specific, there are 5 classes that need to connect the ES cluster and this approach creates a new Transport client for each class.

Is 1) a good approach to go ahead in terms of elastic search, as it is usually not recommended to have singleton db connection object?

Is there any connection pooling mechanism available for Elastic Search, like we have DBCP for relational databases?

like image 850
Ravi Naik Avatar asked Oct 31 '22 11:10

Ravi Naik


1 Answers

Your client should be a singleton. source : http://elasticsearch-users.115913.n3.nabble.com/What-is-your-best-practice-to-access-a-cluster-by-a-Java-client-td4015311.html

like image 108
Maxime Avatar answered Nov 15 '22 04:11

Maxime