Connection pool and session

Hi, I hope you will be fine.

I'm using Neo4j for my application. I want to know about connection pool. In our application we are
running 8 queries asynchronously and handling its using promises. We create promises array and resolve it in promise.all. We handled the session creation and close according to documentation like in finally we close session. But the problem is I saw _pools.element has already 4 elements even before the session creation and also I debugged the case for my queries like I have 8 queries I checked it showed me 8 elements for it in pool but as I'm closing my session in finally and it should close but before sending the response I console the pools elements it still had 8 elements there it seems session.close() is not working because on closing it should remove respective element right? I need to know about this behavior How can i add connection pool length logs accurately.

Thanks

Hi, Syed.

The connections are not closed after the sessions get closed. Connections are returned to pool to be re-used for next sessions. This is for performance reasons since the next sessions won't need re-created connections, handshake, etc. Of course, there is a limit in how much the pool will increase for each address and the driver checks if the connection stills working before give it to the session.

Hi, antonio Thanks for the response.

Hmm So, connection will not closed but would return to pool So that connection can be reused.
and the _pools.elements length will represent the number of connections that our application uses during all execution right? it will not destroy the connection instance?

and 1 more thing lets says my application has maximumPoolSize of 100 and if in my app it hits 101 connections it will throw error immediately because pools.elements length should be 100 right or will not allow to create new 101 connection and will wait for existing connection when they will be idle the next task use it?

The driver won't allow the creation of more connections then needed and then the next transaction will need to wait a bit for connections get released. There is a driver configuration for how much a transaction will wait for a connection be acquired from the pool (Config | Neo4j Bolt Driver 5.x for JavaScript)

And the session only holds the connection whenever they are using in transaction (or session.run), after the transaction finishes, the connection is returned to the pool.

Ok Thanks

last question if new task waits more than configured time for in use connection then it can result in timeout?

Yes, the execution will get an error even before starts. The error will have a message like this Connection acquisition timed out in ${this._acquisitionTimeout} ms. Pool status: Active conn count = ${activeCount}, Idle conn count = ${idleCount}., type equals to Neo4jError and code equals to N/A.

Btw, I don't recommend increase the size of the pool since it can overload the database with threads and make the driver cold start a slower. This type of configuration shouldn't be change without taking in consideration the whole system load and trade-offs involved.

Thanks a lot antonio :)
ok i get it. Again Thanks.