如何获取nodejs mysql连接池中未使用/已使用的连接数?

2024-01-16

我正在使用nodejs连接池和npm的“mysql”模块。 创建池时,我将连接限制指定为 100。 我想知道运行时池中有多少连接被使用/未使用。


通过查看源代码在这里 https://github.com/felixge/node-mysql/blob/master/lib/Pool.js#L10,看来你可以看看:

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()被调用时,它将创建一个新的连接。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何获取nodejs mysql连接池中未使用/已使用的连接数? 的相关文章

随机推荐