Open
Description
In my app, I get a few acquire timeout every day, below is code and log
Code is:
const mysqlPool = app.mysql.pool;
mysqlPool.on('connection', connection => {
app.logger.info(`mysql connection and pool detail: ${connection.threadId} - ${mysqlPoolConnection(mysqlPool)}`, { tid: app.tracerTraceId });
});
mysqlPool.on('acquire', connection => {
app.logger.info(`mysql acquire and pool detail: ${connection.threadId} - ${mysqlPoolConnection(mysqlPool)}`, { tid: app.tracerTraceId });
});
mysqlPool.on('release', connection => {
app.logger.info(`mysql release and pool detail: ${connection.threadId} - ${mysqlPoolConnection(mysqlPool)}`, { tid: app.tracerTraceId });
});
mysqlPool.on('enqueue', connection => {
app.logger.info(`mysql enqueue and pool detail: ${connection.threadId} - ${mysqlPoolConnection(mysqlPool)}`, { tid: app.tracerTraceId });
});
function mysqlPoolConnection(pool) {
return `_allConnections: ${pool._allConnections.length}[ ${getConnectionThreadIds(pool._allConnections)} ], _acquiringConnections: ${pool._acquiringConnections.length} [ ${getConnectionThreadIds(pool._acquiringConnections)} ], _freeConnections: ${pool._freeConnections.length} [ ${getConnectionThreadIds(pool._freeConnections)} ]`;
}
function getConnectionThreadIds(cons) {
return cons.map(con => con.threadId).join(',');
}
And config is
{
host: 'xxx',
port: xxx,
user: 'xxx',
password: 'xxx',
database: 'xxx',
connectionLimit: 10,
connectTimeout: 3000,
acquireTimeout: 4000
}