I get Error Too many connections
when there to much items in a loop with INSERT IGNORE INTO.
function insertCases(cases) {
for(var i in cases) {
var thequery = 'INSERT IGNORE INTO `cases` SET keysused='+cases.keysused+'
pool.query(thequery, function(ee, rr) {
if(ee) {
logger.info(ee);
throw ee;
}
});
}
}
When there are now 100+ cases so 100 times INSERT IGNORE INTO than I get too many connections. I don't know how much exactly crash it but with 100 it's working.
What I read is, that query runs the query and also closes the connection after done, so I read, I don't need to close it after than.
If I run 100, waiting short time and run 100 again and so on, it don't get Too many connections error.
It's only when there runs so much time at once.
That's my DB settings
var db_config = {
connectionLimit : 5000,
host: 'localhost',
user: 'userexample',
password: '*******',
database: 'example.com'
};
and that's the function that createPool.
function database_connection() {
pool = mysql.createPool(db_config);
pool.getConnection(function(err, connection) {
if(err) {
logger.error('[ERROR] Connecting to database "' + err.toString() + '"');
setTimeout(function() { database_connection(); }, 2500);
}
else
{
pool.query('SET NAMES utf8');
pool.query('SET CHARACTER SET utf8');
logger.trace('[INFO] Connected to database and set utf8!');
}
});
}
All queries on the node are simply run with pool.query
The database_connection()
is called on start of the node