0

I've built a Node.js server that uses the node-mysql module to connect to a MySQL server. I use the following piece of code:

var pool = mysql.createPool( 
    {
    connectionLimit : 15,
    waitForConnections : true,
    host     : 'remotehost',
    user     : 'root',
    password : 'pass',
    database : 'master',
    }
);

This works fine most of the time. However, when I leave the page open for some time (about 30 minutes) and reload it, the time taken for features that require a connection to the database to load is significantly longer. Also, it is only the first connection after the wait that takes a long time to establish. What do you think could be the reason for this?

I use the following syntax to return a connection to the pool after making a query:

connection.query("SELECT * FROM logtable", function (err, rows, fields) {
    if (err) throw err;
});
connection.release();
raul
  • 1,209
  • 7
  • 20
  • 36
  • You should only call `connection.release();` inside your callback since that is where you know the query is finished, not immediately following the `query()` since it is asynchronous and non-blocking. – mscdex Sep 30 '14 at 12:22
  • @mscdex: That's how I was doing it earlier. But this code produces the same result too. This can't be the reason for the latency right? – raul Sep 30 '14 at 15:42

0 Answers0