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.
解决方案
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.