How to get number of unused/used connection in nodejs mysql connection pool?

六眼飞鱼酱① 提交于 2019-12-09 05:42:30

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/35195309/how-to-get-number-of-unused-used-connection-in-nodejs-mysql-connection-pool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!