如何在Node.js的MySQL连接池中获取未使用/已使用连接的数量?

10

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

1个回答

19

这里的源代码来看,你可以查看:

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

这个完全正常运作。谢谢。 - Kunjesh Virani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接