加入收藏 | 设为首页 | 会员中心 | 我要投稿 辽源站长网 (https://www.0437zz.com/)- 云专线、云连接、智能数据、边缘计算、数据安全!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

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

发布时间:2021-04-01 02:03:51 所属栏目:MySql教程 来源:网络整理
导读:我正在使用nodejs连接池,使用npm的“mysql”模块. 在创建池时,我已将connectionLimit指定为100. 我想知道在运行时有多少个连接在池中使用/未使用.最佳答案通过查看the source code here,您可以看到: pool.config.connectionLimit // passed in max size of

我正在使用nodejs连接池,使用npm的“mysql”模块.
在创建池时,我已将connectionLimit指定为100.
我想知道在运行时有多少个连接在池中使用/未使用. 最佳答案 通过查看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()时,它将创建一个新连接.

(编辑:辽源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读