node-mysql2
node-mysql2 copied to clipboard
First query is super slow, all others are fine
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
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 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 Is it still happening?