# Java API Client Object init performance

**URL:** <https://discuss.elastic.co/t/java-api-client-object-init-performance/5645>\
**Category:** Elasticsearch\
**Created:** [October 19, 2011, 7:29pm UTC](https://discuss.elastic.co/t/java-api-client-object-init-performance/5645 "2011-10-19T19:29:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![alichi](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@alichi](https://discuss.elastic.co/u/alichi)\
**Post date:** [October 19, 2011, 7:29pm UTC](https://discuss.elastic.co/t/java-api-client-object-init-performance/5645/1 "2011-10-19T19:29:47Z")

</div>

I am designing a new service layer using ES Java API. I have got  
couple of questions (I have not looked into ES source code yet)?

Based on your experience:  
1- How many concurrent (per second, 2 million docs, response time less  
than 100ms, large ec2 instance) requests can a singleton Client object  
handle?

2- How heavy Client initialization is (based on answer to the question  
above)?  
a- Client initialization is heavy, then I will need to create a  
pool of the clients.  
b- Client initialization is super fast, then I will just create  
them as I the need comes.

---

<div class="post-metadata">

**Author:** ![avasilenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avasilenko/32/2901_2.png) [@avasilenko](https://discuss.elastic.co/u/avasilenko)\
**Post date:** [October 19, 2011, 7:48pm UTC](https://discuss.elastic.co/t/java-api-client-object-init-performance/5645/2 "2011-10-19T19:48:28Z")

</div>

Hello Ali,

I don't have ES experience in production, but I made some debugging during  
development.  
As far as I understood each client requires initializing local node,  
registering node in cluster, build pool of connection threads (to speak with  
other nodes). If it's node with data - initialize shards, rebalance cluster.  
So a best option would be to have single node per JVM. If you see that you  
lack of connections, increase connection pool of client.

Regards,  
Alexandr Vasilenko

2011/10/19 Ali [loghmani@gmail.com](mailto:loghmani@gmail.com)

> I am designing a new service layer using ES Java API. I have got  
> couple of questions (I have not looked into ES source code yet)?
> 
> Based on your experience:  
> 1- How many concurrent (per second, 2 million docs, response time less  
> than 100ms, large ec2 instance) requests can a singleton Client object  
> handle?
> 
> 2- How heavy Client initialization is (based on answer to the question  
> above)?  
> a- Client initialization is heavy, then I will need to create a  
> pool of the clients.  
> b- Client initialization is super fast, then I will just create  
> them as I the need comes.

---

<div class="post-metadata">

**Author:** ![alichi](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@alichi](https://discuss.elastic.co/u/alichi)\
**Post date:** [October 19, 2011, 8:00pm UTC](https://discuss.elastic.co/t/java-api-client-object-init-performance/5645/3 "2011-10-19T20:00:55Z")

</div>

Hi Alex,  
Thanks for your quick response, I agree with you that it is better to  
have one "node" per JVM. However, I was wondering if I could obtain  
several "Client" objects from one "node" in case I needed to (I am not  
sure if it is even needed, please read on)! Correct me if I am wrong,  
so client works just like a facade handing over requests to a pool of  
threads managed by the node class?  
If it is the case then I need to have one singleton instance of "node"  
and just obtain one "Client" from it, and if the load picks up it  
means that I have to add a new box, right?

To give you a better picture, I am creating a high level API on top of  
ES so I do not want to introduce any performance bottlenecks, and this  
is why I try to understand how node-client bundle work.  
Thanks,  
Ali

On Oct 19, 12:48 pm, Alex Vasilenko [aa.vasile...@gmail.com](mailto:aa.vasile...@gmail.com) wrote:

> Hello Ali,
> 
> I don't have ES experience in production, but I made some debugging during  
> development.  
> As far as I understood each client requires initializing local node,  
> registering node in cluster, build pool of connection threads (to speak with  
> other nodes). If it's node with data - initialize shards, rebalance cluster.  
> So a best option would be to have single node per JVM. If you see that you  
> lack of connections, increase connection pool of client.
> 
> Regards,  
> Alexandr Vasilenko
> 
> 2011/10/19 Ali [loghm...@gmail.com](mailto:loghm...@gmail.com)
> 
> > I am designing a new service layer using ES Java API. I have got  
> > couple of questions (I have not looked into ES source code yet)?
> 
> > Based on your experience:  
> > 1- How many concurrent (per second, 2 million docs, response time less  
> > than 100ms, large ec2 instance) requests can a singleton Client object  
> > handle?
> 
> > 2- How heavy Client initialization is (based on answer to the question  
> > above)?  
> > a- Client initialization is heavy, then I will need to create a  
> > pool of the clients.  
> > b- Client initialization is super fast, then I will just create  
> > them as I the need comes.

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [October 19, 2011, 8:23pm UTC](https://discuss.elastic.co/t/java-api-client-object-init-performance/5645/4 "2011-10-19T20:23:41Z")

</div>

Hi,

If you are talking about Node client then I think each Node maintains  
singleton instance of client, so each call to .client() method on Node  
returns you the same instance of client. (see NodeClientModule code  
[https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClientModule.java](https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClientModule.java)  
).

Regards,  
Lukas

On Wed, Oct 19, 2011 at 10:00 PM, Ali [loghmani@gmail.com](mailto:loghmani@gmail.com) wrote:

> Hi Alex,  
> Thanks for your quick response, I agree with you that it is better to  
> have one "node" per JVM. However, I was wondering if I could obtain  
> several "Client" objects from one "node" in case I needed to (I am not  
> sure if it is even needed, please read on)! Correct me if I am wrong,  
> so client works just like a facade handing over requests to a pool of  
> threads managed by the node class?  
> If it is the case then I need to have one singleton instance of "node"  
> and just obtain one "Client" from it, and if the load picks up it  
> means that I have to add a new box, right?
> 
> To give you a better picture, I am creating a high level API on top of  
> ES so I do not want to introduce any performance bottlenecks, and this  
> is why I try to understand how node-client bundle work.  
> Thanks,  
> Ali
> 
> On Oct 19, 12:48 pm, Alex Vasilenko [aa.vasile...@gmail.com](mailto:aa.vasile...@gmail.com) wrote:
> 
> > Hello Ali,
> > 
> > I don't have ES experience in production, but I made some debugging  
> > during  
> > development.  
> > As far as I understood each client requires initializing local node,  
> > registering node in cluster, build pool of connection threads (to speak  
> > with  
> > other nodes). If it's node with data - initialize shards, rebalance  
> > cluster.  
> > So a best option would be to have single node per JVM. If you see that  
> > you  
> > lack of connections, increase connection pool of client.
> > 
> > Regards,  
> > Alexandr Vasilenko
> > 
> > 2011/10/19 Ali [loghm...@gmail.com](mailto:loghm...@gmail.com)
> > 
> > > I am designing a new service layer using ES Java API. I have got  
> > > couple of questions (I have not looked into ES source code yet)?
> > 
> > > Based on your experience:  
> > > 1- How many concurrent (per second, 2 million docs, response time less  
> > > than 100ms, large ec2 instance) requests can a singleton Client object  
> > > handle?
> > 
> > > 2- How heavy Client initialization is (based on answer to the question  
> > > above)?  
> > > a- Client initialization is heavy, then I will need to create a  
> > > pool of the clients.  
> > > b- Client initialization is super fast, then I will just create  
> > > them as I the need comes.

---

<div class="post-metadata">

**Author:** ![alichi](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@alichi](https://discuss.elastic.co/u/alichi)\
**Post date:** [October 19, 2011, 8:41pm UTC](https://discuss.elastic.co/t/java-api-client-object-init-performance/5645/5 "2011-10-19T20:41:21Z")

</div>

Hi Lukas,  
You actually demystified it for me, ... One Node and one Client per  
JVM, that is what I gotta do, and I have to create my DAO layer on top  
of it ... I guess I got to look into Compass source code too.  
Thanks,  
Ali

On Oct 19, 1:23 pm, Lukáš Vlček [lukas.vl...@gmail.com](mailto:lukas.vl...@gmail.com) wrote:

> Hi,
> 
> If you are talking about Node client then I think each Node maintains  
> singleton instance of client, so each call to .client() method on Node  
> returns you the same instance of client. (see NodeClientModule codehttps://github.com/elasticsearch/elasticsearch/blob/master/modules/el...  
> ).
> 
> Regards,  
> Lukas
> 
> On Wed, Oct 19, 2011 at 10:00 PM, Ali [loghm...@gmail.com](mailto:loghm...@gmail.com) wrote:
> 
> > Hi Alex,  
> > Thanks for your quick response, I agree with you that it is better to  
> > have one "node" per JVM. However, I was wondering if I could obtain  
> > several "Client" objects from one "node" in case I needed to (I am not  
> > sure if it is even needed, please read on)! Correct me if I am wrong,  
> > so client works just like a facade handing over requests to a pool of  
> > threads managed by the node class?  
> > If it is the case then I need to have one singleton instance of "node"  
> > and just obtain one "Client" from it, and if the load picks up it  
> > means that I have to add a new box, right?
> 
> > To give you a better picture, I am creating a high level API on top of  
> > ES so I do not want to introduce any performance bottlenecks, and this  
> > is why I try to understand how node-client bundle work.  
> > Thanks,  
> > Ali
> 
> > On Oct 19, 12:48 pm, Alex Vasilenko [aa.vasile...@gmail.com](mailto:aa.vasile...@gmail.com) wrote:
> > 
> > > Hello Ali,
> 
> > > I don't have ES experience in production, but I made some debugging  
> > > during  
> > > development.  
> > > As far as I understood each client requires initializing local node,  
> > > registering node in cluster, build pool of connection threads (to speak  
> > > with  
> > > other nodes). If it's node with data - initialize shards, rebalance  
> > > cluster.  
> > > So a best option would be to have single node per JVM. If you see that  
> > > you  
> > > lack of connections, increase connection pool of client.
> 
> > > Regards,  
> > > Alexandr Vasilenko
> 
> > > 2011/10/19 Ali [loghm...@gmail.com](mailto:loghm...@gmail.com)
> 
> > > > I am designing a new service layer using ES Java API. I have got  
> > > > couple of questions (I have not looked into ES source code yet)?
> 
> > > > Based on your experience:  
> > > > 1- How many concurrent (per second, 2 million docs, response time less  
> > > > than 100ms, large ec2 instance) requests can a singleton Client object  
> > > > handle?
> 
> > > > 2- How heavy Client initialization is (based on answer to the question  
> > > > above)?  
> > > > a- Client initialization is heavy, then I will need to create a  
> > > > pool of the clients.  
> > > > b- Client initialization is super fast, then I will just create  
> > > > them as I the need comes.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [October 19, 2011, 9:08pm UTC](https://discuss.elastic.co/t/java-api-client-object-init-performance/5645/6 "2011-10-19T21:08:09Z")

</div>

Yes, one client instance is enough, no need to pull it (either  
TransportClient no Node client).

On Wed, Oct 19, 2011 at 10:41 PM, Ali [loghmani@gmail.com](mailto:loghmani@gmail.com) wrote:

> Hi Lukas,  
> You actually demystified it for me, ... One Node and one Client per  
> JVM, that is what I gotta do, and I have to create my DAO layer on top  
> of it ... I guess I got to look into Compass source code too.  
> Thanks,  
> Ali
> 
> On Oct 19, 1:23 pm, Lukáš Vlček [lukas.vl...@gmail.com](mailto:lukas.vl...@gmail.com) wrote:
> 
> > Hi,
> > 
> > If you are talking about Node client then I think each Node maintains  
> > singleton instance of client, so each call to .client() method on Node  
> > returns you the same instance of client. (see NodeClientModule  
> > codehttps://github.com/elasticsearch/elasticsearch/blob/master/modules/el.  
> > ..  
> > ).
> > 
> > Regards,  
> > Lukas
> > 
> > On Wed, Oct 19, 2011 at 10:00 PM, Ali [loghm...@gmail.com](mailto:loghm...@gmail.com) wrote:
> > 
> > > Hi Alex,  
> > > Thanks for your quick response, I agree with you that it is better to  
> > > have one "node" per JVM. However, I was wondering if I could obtain  
> > > several "Client" objects from one "node" in case I needed to (I am not  
> > > sure if it is even needed, please read on)! Correct me if I am wrong,  
> > > so client works just like a facade handing over requests to a pool of  
> > > threads managed by the node class?  
> > > If it is the case then I need to have one singleton instance of "node"  
> > > and just obtain one "Client" from it, and if the load picks up it  
> > > means that I have to add a new box, right?
> > 
> > > To give you a better picture, I am creating a high level API on top of  
> > > ES so I do not want to introduce any performance bottlenecks, and this  
> > > is why I try to understand how node-client bundle work.  
> > > Thanks,  
> > > Ali
> > 
> > > On Oct 19, 12:48 pm, Alex Vasilenko [aa.vasile...@gmail.com](mailto:aa.vasile...@gmail.com) wrote:
> > > 
> > > > Hello Ali,
> > 
> > > > I don't have ES experience in production, but I made some debugging  
> > > > during  
> > > > development.  
> > > > As far as I understood each client requires initializing local node,  
> > > > registering node in cluster, build pool of connection threads (to  
> > > > speak  
> > > > with  
> > > > other nodes). If it's node with data - initialize shards, rebalance  
> > > > cluster.  
> > > > So a best option would be to have single node per JVM. If you see  
> > > > that  
> > > > you  
> > > > lack of connections, increase connection pool of client.
> > 
> > > > Regards,  
> > > > Alexandr Vasilenko
> > 
> > > > 2011/10/19 Ali [loghm...@gmail.com](mailto:loghm...@gmail.com)
> > 
> > > > > I am designing a new service layer using ES Java API. I have got  
> > > > > couple of questions (I have not looked into ES source code yet)?
> > 
> > > > > Based on your experience:  
> > > > > 1- How many concurrent (per second, 2 million docs, response time  
> > > > > less  
> > > > > than 100ms, large ec2 instance) requests can a singleton Client  
> > > > > object  
> > > > > handle?
> > 
> > > > > 2- How heavy Client initialization is (based on answer to the  
> > > > > question  
> > > > > above)?  
> > > > > a- Client initialization is heavy, then I will need to create a  
> > > > > pool of the clients.  
> > > > > b- Client initialization is super fast, then I will just create  
> > > > > them as I the need comes.

---

<div class="post-metadata">

**Author:** ![alichi](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@alichi](https://discuss.elastic.co/u/alichi)\
**Post date:** [October 19, 2011, 9:57pm UTC](https://discuss.elastic.co/t/java-api-client-object-init-performance/5645/7 "2011-10-19T21:57:50Z")

</div>

Thanks Shay

On Oct 19, 2:08 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Yes, one client instance is enough, no need to pull it (either  
> TransportClient no Node client).
> 
> On Wed, Oct 19, 2011 at 10:41 PM, Ali [loghm...@gmail.com](mailto:loghm...@gmail.com) wrote:
> 
> > Hi Lukas,  
> > You actually demystified it for me, ... One Node and one Client per  
> > JVM, that is what I gotta do, and I have to create my DAO layer on top  
> > of it ... I guess I got to look into Compass source code too.  
> > Thanks,  
> > Ali
> 
> > On Oct 19, 1:23 pm, Lukáš Vlček [lukas.vl...@gmail.com](mailto:lukas.vl...@gmail.com) wrote:
> > 
> > > Hi,
> 
> > > If you are talking about Node client then I think each Node maintains  
> > > singleton instance of client, so each call to .client() method on Node  
> > > returns you the same instance of client. (see NodeClientModule  
> > > codehttps://github.com/elasticsearch/elasticsearch/blob/master/modules/el.  
> > > ..  
> > > ).
> 
> > > Regards,  
> > > Lukas
> 
> > > On Wed, Oct 19, 2011 at 10:00 PM, Ali [loghm...@gmail.com](mailto:loghm...@gmail.com) wrote:
> > > 
> > > > Hi Alex,  
> > > > Thanks for your quick response, I agree with you that it is better to  
> > > > have one "node" per JVM. However, I was wondering if I could obtain  
> > > > several "Client" objects from one "node" in case I needed to (I am not  
> > > > sure if it is even needed, please read on)! Correct me if I am wrong,  
> > > > so client works just like a facade handing over requests to a pool of  
> > > > threads managed by the node class?  
> > > > If it is the case then I need to have one singleton instance of "node"  
> > > > and just obtain one "Client" from it, and if the load picks up it  
> > > > means that I have to add a new box, right?
> 
> > > > To give you a better picture, I am creating a high level API on top of  
> > > > ES so I do not want to introduce any performance bottlenecks, and this  
> > > > is why I try to understand how node-client bundle work.  
> > > > Thanks,  
> > > > Ali
> 
> > > > On Oct 19, 12:48 pm, Alex Vasilenko [aa.vasile...@gmail.com](mailto:aa.vasile...@gmail.com) wrote:
> > > > 
> > > > > Hello Ali,
> 
> > > > > I don't have ES experience in production, but I made some debugging  
> > > > > during  
> > > > > development.  
> > > > > As far as I understood each client requires initializing local node,  
> > > > > registering node in cluster, build pool of connection threads (to  
> > > > > speak  
> > > > > with  
> > > > > other nodes). If it's node with data - initialize shards, rebalance  
> > > > > cluster.  
> > > > > So a best option would be to have single node per JVM. If you see  
> > > > > that  
> > > > > you  
> > > > > lack of connections, increase connection pool of client.
> 
> > > > > Regards,  
> > > > > Alexandr Vasilenko
> 
> > > > > 2011/10/19 Ali [loghm...@gmail.com](mailto:loghm...@gmail.com)
> 
> > > > > > I am designing a new service layer using ES Java API. I have got  
> > > > > > couple of questions (I have not looked into ES source code yet)?
> 
> > > > > > Based on your experience:  
> > > > > > 1- How many concurrent (per second, 2 million docs, response time  
> > > > > > less  
> > > > > > than 100ms, large ec2 instance) requests can a singleton Client  
> > > > > > object  
> > > > > > handle?
> 
> > > > > > 2- How heavy Client initialization is (based on answer to the  
> > > > > > question  
> > > > > > above)?  
> > > > > > a- Client initialization is heavy, then I will need to create a  
> > > > > > pool of the clients.  
> > > > > > b- Client initialization is super fast, then I will just create  
> > > > > > them as I the need comes.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:51am UTC](https://discuss.elastic.co/t/java-api-client-object-init-performance/5645/8 "2017-07-06T03:51:19Z")

</div>


