Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is ElasticClient thread safe? (connection pooling) #385

Closed
janghwan opened this issue Aug 20, 2015 · 4 comments
Closed

is ElasticClient thread safe? (connection pooling) #385

janghwan opened this issue Aug 20, 2015 · 4 comments

Comments

@janghwan
Copy link

@janghwan janghwan commented Aug 20, 2015

Hi guys.
I wonder what's the best usage of ElasticClient
Is it okay - in terms of performance - to call ElasticClient.remote() every time I need a client?
Or should I cache a singleton object and share among threads?

@andrestc
Copy link
Contributor

@andrestc andrestc commented Aug 21, 2015

We are currently using it as a singleton object. I think all that ElasticClient does is create an org.elasticsearch.client.transport.TransportClient. It seems that he keeps a pool of threads for sending the requests over the cluster; so i don't think its a good idea to call it every time when making a request.

@sksamuel
Copy link
Owner

@sksamuel sksamuel commented Aug 21, 2015

@janghwan Definitely cache it. The reason is an Elasticsearch client is a clever beast. It pings the cluster to become cluster-aware so it can route queries to the right nodes. Each time you create one there's this small overhead. In addition to the internal thread pools it creates (about 30 threads).

@janghwan
Copy link
Author

@janghwan janghwan commented Aug 21, 2015

@sksamuel sksamuel closed this Aug 21, 2015
@fpopic
Copy link

@fpopic fpopic commented Sep 2, 2016


object Elastic4sUtils {

  val client = ElasticClient.transport("elasticsearch://localhost:9300")

}

Is that good example of it or ?

val session = Elastic4sUtils.client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.