mysql icon indicating copy to clipboard operation
mysql copied to clipboard

MySQL AWS too many connection

Open kushalhyperlink opened this issue 5 years ago • 4 comments
trafficstars

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;
            });
        });
    };

kushalhyperlink avatar Feb 19 '20 09:02 kushalhyperlink

man look this : https://github.com/jurimengs/monkey

base on springboot, memory database , persistant to mysql with custom strategy

jurimengs avatar Feb 25 '20 16:02 jurimengs

@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 avatar Mar 19 '20 21:03 akleiber

@akleiber facing a similar issue, the default for AWS RDS is 28800. what should be idle acquireTimeout?

a7urag avatar Apr 15 '20 19:04 a7urag

use pool.end(),not connection.release()

c-y-q avatar Jun 19 '20 09:06 c-y-q