Why does the same query take about 300 ms more than the actual runtime when using the native Mysql driver for Nodejs, even with or without the option to create a pool?
Please refer to the highlighted section in the screenshot below.

Also for the runtime of the built-in driver, see the screenshot below:

Codebase for node.js Mysql Native driver
db.js
var mysql = require('mysql');
var connectionpool = mysql.createPool({
connectionLimit: 100,
host: 'localhost',
user: config.development.username,
password: config.development.password,
database: config.development.database,
multipleStatements: true,
});
exports.getConnection = function(callback) {
connectionpool.getConnection(callback);
};
emp.js
var connections = require('../config/db');
var pre_query = new Date().getTime();
var sqlstatements = "select * from employees where recordstate<>'raw'and DATE(createdAt) " + "between ('1982-03-24') and ('2017-04-23') order by employeesID desc limit 20 offset 0;" + "select COUNT(*) as count from employees where recordstate<>'raw'and " + "DATE(createdAt) between ('1982-03-24') and ('2017-04-23') order by employeesID desc";
connections.getConnection(function(err, c) {
console.log(sqlstatements)
c.query(sqlstatements, function(err, projects) {
console.log(err);
if (!err) {
c.release();
var red = new Object();
red.rows = JSON.parse(JSON.stringify(projects[0]));
red.count = JSON.parse(JSON.stringify(projects[1]))[0].count;
var post_query = new Date().getTime();
var duration = (post_query - pre_query) / 1000;
console.log(duration)
res.json(red);
}
})
})
source
share