如何在 nodejs mysql 连接池中获取 unused/used 连接数?
How to get number of unused/used connection in nodejs mysql connection pool?
我正在使用 nodejs 连接池和 npm 的 "mysql" 模块。
在创建池时,我将 connectionLimit 指定为 100。
我想知道在运行时我有多少连接来自池used/unused。
通过查看 the source code here,您似乎可以查看:
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
注意:根据需要创建新连接,直到达到池的最大大小,因此 _freeConnections.length
可能为零,但限制中还有更多连接,因此下一次 .getConnection()
是调用,它将创建一个新连接。
我正在使用 nodejs 连接池和 npm 的 "mysql" 模块。 在创建池时,我将 connectionLimit 指定为 100。 我想知道在运行时我有多少连接来自池used/unused。
通过查看 the source code here,您似乎可以查看:
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
注意:根据需要创建新连接,直到达到池的最大大小,因此 _freeConnections.length
可能为零,但限制中还有更多连接,因此下一次 .getConnection()
是调用,它将创建一个新连接。