node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

First query is super slow, all others are fine

Open anthonywebb opened this issue 6 years ago • 3 comments

This appears to be happening with mysql 8.0.13 (provisioned with amazon RDS), mysql 5.7 does not do this.

What happens is that the first query, any query at all, will take about 8 seconds to run, but all other subsequent queries are nice and fast. Here is the code to reproduce:

var mysql = require('mysql2');

var conn  = mysql.createPool({
    host     : process.env.DB_HOST,
    user     : process.env.DB_USERNAME,
    password : process.env.DB_PASSWORD,
    port     : process.env.DB_PORT,
    database : process.env.DB_NAME
});

console.time('startupQueryTime')
conn.query('SELECT 1+1', [], function(err, result){
    console.timeEnd('startupQueryTime');
})

Output is:

startupQueryTime: 7120.876ms

anthonywebb avatar Feb 09 '19 21:02 anthonywebb

Can you check same setup using mysqljs/mysql driver? Do you experience first slow query only after some inactivity or every time you run script first query is slow ( RDS slow cold start?)

sidorares avatar Feb 10 '19 22:02 sidorares

@sidorares I can verify that this also happening with the normal nodejs "mysql" module, and it only happens on startup, Oddly I have been getting the ECONNRESET error after inactivity. I may have to revert back to mysql 5.7, but I would love to get the enhancements from 8.* if at all possible.

anthonywebb avatar Feb 11 '19 02:02 anthonywebb

@anthonywebb Is it still happening?

testn avatar Oct 28 '21 15:10 testn