# Connection pool in Aerospike Java Client does not limit number of connections

**URL:** <https://discuss.aerospike.com/t/connection-pool-in-aerospike-java-client-does-not-limit-number-of-connections/3434>\
**Category:** Java Client\
**Created:** [September 21, 2016, 9:15am UTC](https://discuss.aerospike.com/t/connection-pool-in-aerospike-java-client-does-not-limit-number-of-connections/3434 "2016-09-21T09:15:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankur\_hani](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@ankur\_hani](https://discuss.aerospike.com/u/ankur_hani)\
**Post date:** [September 21, 2016, 9:15am UTC](https://discuss.aerospike.com/t/connection-pool-in-aerospike-java-client-does-not-limit-number-of-connections/3434/1 "2016-09-21T09:15:47Z")

</div>

Aerospike Client Version : 3.1.6 Method : getConnection() Problem : Method get Connection never tracks the number of open connections in the pool. If at any point ‘n’ threads call this method at the same time, and existing queue does not contain any **valid** connection, all will be returned with a new Connection. Therefore, the property **_maxThreads_** is not honored by the client. Please check and explain the reasons for such a design if it is intended.

Code Snippet :

> while ((conn = (Connection)this.connectionQueue.poll()) != null) { /\* 210 _/ if (conn.isValid()) { /__/ try { /_ 212 _/ conn.setTimeout(timeoutMillis); /_ 213 _/ return conn; /__/ / __/ } /__ / catch (Exception e) /__/ { /_ 218 _/ conn.close(); /_ 219 _/ throw new AerospikeException.Connection(e); /__/ } /__/ } /_ 222 _/ conn.close(); /__/ } /_ 224 \*/ Connection conn = new Connection(this.address, timeoutMillis, this.cluster.maxSocketIdleMillis);

---

<div class="post-metadata">

**Author:** ![Brian](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/brian/32/2211_2.png) [@Brian](https://discuss.aerospike.com/u/Brian)\
**Post date:** [September 21, 2016, 5:14pm UTC](https://discuss.aerospike.com/t/connection-pool-in-aerospike-java-client-does-not-limit-number-of-connections/3434/2 "2016-09-21T17:14:38Z")

</div>

Java client versions 3.2.0+ will enforce max connections.

[http://www.aerospike.com/download/client/java/notes.html#3.2.0](http://www.aerospike.com/download/client/java/notes.html#3.2.0)

---

<div class="post-metadata">

**Author:** ![ankur\_hani](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@ankur\_hani](https://discuss.aerospike.com/u/ankur_hani)\
**Post date:** [September 22, 2016, 6:47am UTC](https://discuss.aerospike.com/t/connection-pool-in-aerospike-java-client-does-not-limit-number-of-connections/3434/3 "2016-09-22T06:47:51Z")

</div>

Hi Brian,

Thanks for your reply. I checked the linked mentioned and it says below:

> Enforce maxConnsPerNode as a hard limit. **Return new result code NO\_MORE\_CONNECTIONS if this limit would be exceeded.**

Would this mean client will throw an error if we call get Connection more than configured **maxConnsPerNode** times parallely. It also does not seem a valid behaviour. It should wait for the connection to be freed in the pool instead of throwing the error.

Please confirm.

---

<div class="post-metadata">

**Author:** ![Brian](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/brian/32/2211_2.png) [@Brian](https://discuss.aerospike.com/u/Brian)\
**Post date:** [September 22, 2016, 7:01pm UTC](https://discuss.aerospike.com/t/connection-pool-in-aerospike-java-client-does-not-limit-number-of-connections/3434/4 "2016-09-22T19:01:16Z")

</div>

Yes, the client throws an exception with result code NO\_MORE\_CONNECTIONS by design.

One of the complaints about the old soft limit was that there was a silent performance and resource usage penalty when max connections were exceeded.

If the client waited for an available connection, there would be more contention that would again result in a silent performance penalty. The new hard limit is explicit and requires the user to take action.

---

<div class="post-metadata">

**Author:** ![ankur\_hani](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@ankur\_hani](https://discuss.aerospike.com/u/ankur_hani)\
**Post date:** [September 23, 2016, 5:44am UTC](https://discuss.aerospike.com/t/connection-pool-in-aerospike-java-client-does-not-limit-number-of-connections/3434/5 "2016-09-23T05:44:12Z")

</div>

Thanks Brian for the insights.
