I am using nodejs connection pooling, with npm's "mysql" module. While creating a pool I have specified the connectionLimit as 100. I would like to know how many of my connections are used/unused from the pool at runtime.
The Node. js driver supports connection pooling. Connection pooling allows your application to reuse existing connections by automatically saving the connection to a pool so it can be reused, rather than repeatedly creating a new connection to the SAP HANA database server.
For optimal performance, use a pool with eight to 16 connections per node. For example, if you have four nodes configured, then the steady-pool size must be set to 32 and the maximum pool size must be 64.
js MySQL Count() Function. We use the COUNT() function in MySQL to count a number of rows in a column satisfying the WHERE clause. Parameters: COUNT() function accepts a single parameter as mentioned above and described below.
If connectionLimit is 10, the maximum number of connections that the driver will make to the database is 10.
By looking at the source code here, it appears that you can look at:
pool.config.connectionLimit // passed in max size of the pool
pool._freeConnections.length // number of free connections awaiting use
pool._allConnections.length // number of connections currently created, including ones in use
pool._acquiringConnections.length // number of connections in the process of being acquired
Note: New connections are created as needed up to the max size of the pool so _freeConnections.length
could be zero, but there are many more connections in the limit so the next time .getConnection()
is called, it will create a new connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With