我正在使用npm的“mysql”模块和nodejs连接池技术。 在创建连接池时,我将连接数限制为100个。 我想知道在运行时有多少连接被使用或未使用。
我正在使用npm的“mysql”模块和nodejs连接池技术。 在创建连接池时,我将连接数限制为100个。 我想知道在运行时有多少连接被使用或未使用。
从这里的源代码来看,你可以查看:
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()
时,它将创建一个新连接。