5

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?

Ravi Naik
  • 554
  • 5
  • 6

2 Answers2

0

It doesn't have to be a singleton client (by "singleton" i mean an instance that can be initialized only once). you can save a state of the client's instance and pass it as a parameter between your application modules. this way you won't limit your application to use only one client resource.

i also attach a good reference about why singeltons are bad

Community
  • 1
  • 1
nivpenso
  • 283
  • 3
  • 17