mysql
mysql copied to clipboard
MySQL AWS too many connection
Hello Team,
I am having an issue with too many connections, I check the Process having too many process and process are not being released.
I have used below code
const pool = require('mysql').createPool({
connectionLimit : 1000,
connectTimeout : 60 * 60 * 1000,
acquireTimeout : 60 * 60 * 1000,
timeout : 60 * 60 * 1000,
host : process.env.DB_HOST,
user : process.env.DB_USERNAME,
password : process.env.DB_PASSWORD,
database : process.env.DB_DATABASE,
dateStrings : 'date',
charset : 'utf8mb4'
});
var DB = (function () {
function _query(query, params, callback) {
// console.log(query);
pool.getConnection(function (err, connection) {
if (err) {
console.log(err);
callback(err, null);
throw err;
}
connection.query(query, params, function (err, rows, fields) {
connection.release();
if (!err) {
callback(null, rows, fields);
}
else {
console.log('connection release 1: ',err);
callback(err, null);
}
});
connection.on('release', function (connection) {
console.log('Connection %d released', connection.threadId);
});
pool.on('release', function (connection) {
console.log('Connection %d released', connection.threadId);
});
connection.on('error', function (err) {
connection.release();
console.log('connection release 2: ',err);
callback(err, null);
throw err;
});
});
};
man look this : https://github.com/jurimengs/monkey
base on springboot, memory database , persistant to mysql with custom strategy
@kushalhyperlink check our wait_timeout- the default for AWS RDS is 28800.
The pool will never close the connections that are aquired, i.e. they will stay open for 28800 seconds.
Check:
SELECT @@global.wait_timeout, @@session.wait_timeout, @@global.interactive_timeout, @@session.interactive_timeout
@akleiber facing a similar issue, the default for AWS RDS is 28800. what should be idle acquireTimeout?
use pool.end(),not connection.release()