You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have found during load testings (2000 concurrent users) that mysqljs /mysql connection pool uses tons of connections (more than 3000) and those connections are not really closed on client side after the run is over, even I call connection.release() after each query. They are just put into sleep mode. It relies on mysql server to destroy those connections after a certain idling time (by default 24 hours on Aurora).
In most applications I worked on, the client is responsible for disconnecting the connection after idling/stuck/sleep, not by the db server. So to me, this library behaves differently. There is a node mysql-connection-pool-manager module created to make up this gap by periodically destroying the long idling connections. However, I still want to use mysqljs/mysql as my codebase is written on this.
My question is why mysqljs/mysql does not offer this option to do the same cleaning up on client side? The pool.end() does this but this should be only invoked when the application terminates.
If I call connection.destroy() every-time my query is done, will it actually destroy the connection? I am afraid if I call destroy, then the pool won't be able to reuse the connection and cause performance issue.
Also, regarding the high connection usages, does the connection.release() a synchronous call? because I notice one user sometimes needs 2 connections even I execute my queries sequentially (excluding the connection.release()).
Please help.
Thanks.
Richard
The text was updated successfully, but these errors were encountered:
Waiting some news about this feature and the PR, I have implemented something like this. This is working fine in my production.
TS
constgetConnectionFromPool=(pool: mysql.Pool): Promise<mysql.PoolConnection>=>{returnnewPromise((resolve,reject)=>{pool.getConnection((err: mysql.MysqlError,connection: mysql.PoolConnection)=>{if(err){debug(`Cant get connection from pool`)returnreject(err)}// This is a provissory solution waiting this pull request https://github.com/mysqljs/mysql/pull/2218constconnectionIdleTimer=(connectionasany).__idleCloseTimerif(connectionIdleTimer){clearTimeout(connectionIdleTimer)};(connectionasany).__idleCloseTimer=setTimeout(()=>{debug('close connection due inactivity')(poolasany)._purgeConnection(connection)},30*1000)returnresolve(connection)})})}
JS:
constgetConnectionFromPool=pool=>{returnnewPromise((resolve,reject)=>{pool.getConnection((err,connection)=>{if(err){debug(`Cant get connection from pool`)returnreject(err)}// This is a provissory solution waiting this pull request https://github.com/mysqljs/mysql/pull/2218constconnectionIdleTimer=connection.__idleCloseTimerif(connectionIdleTimer){clearTimeout(connectionIdleTimer)}connection.__idleCloseTimer=setTimeout(()=>{debug('close connection due inactivity')pool._purgeConnection(connection)},30*1000)returnresolve(connection)})})}
I have found during load testings (2000 concurrent users) that mysqljs /mysql connection pool uses tons of connections (more than 3000) and those connections are not really closed on client side after the run is over, even I call connection.release() after each query. They are just put into sleep mode. It relies on mysql server to destroy those connections after a certain idling time (by default 24 hours on Aurora).
In most applications I worked on, the client is responsible for disconnecting the connection after idling/stuck/sleep, not by the db server. So to me, this library behaves differently. There is a node mysql-connection-pool-manager module created to make up this gap by periodically destroying the long idling connections. However, I still want to use mysqljs/mysql as my codebase is written on this.
My question is why mysqljs/mysql does not offer this option to do the same cleaning up on client side? The pool.end() does this but this should be only invoked when the application terminates.
If I call connection.destroy() every-time my query is done, will it actually destroy the connection? I am afraid if I call destroy, then the pool won't be able to reuse the connection and cause performance issue.
Also, regarding the high connection usages, does the connection.release() a synchronous call? because I notice one user sometimes needs 2 connections even I execute my queries sequentially (excluding the connection.release()).
Please help.
Thanks.
Richard
The text was updated successfully, but these errors were encountered: