Why is query execution time so high ?
See original GitHub issueWhy does same query take around 300 ms more than actual execution time when using Mysql native driver for Nodejs , even with or without using “create pool” options?
Please refer highlighted section in below attached screenshot
Also for native driver execution time, please see below attached screenshot:
Codebase for node.js Mysql Native driver
db.js
var mysql = require('mysql');
var connectionpool = mysql.createPool({
connectionLimit: 100, //important
host: 'localhost',
user: "your user name",
password: "your password",
database: "your database",
multipleStatements: true,
});
exports.getConnection = function(callback) {
connectionpool.getConnection(callback);
};
emp.js
var connections = require('../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();
// calculate the duration in seconds
var duration = (post_query - pre_query) / 1000;
console.log(duration)
// console.log(red);
}
})
})
Issue Analytics
- State:
- Created 6 years ago
- Comments:21 (12 by maintainers)
Top Results From Across the Web
Why is query execution time so high for Mysql Native driver ...
The connection setup time depends on many factors (server load, connection speed, configuration etc.). Hard to give any fixed ratio for that, ...
Read more >Slow Queries? Move Fast to Fix Them - Orange Matter
The query profiler in Database Performance Monitor (DPM) can show you top queries consuming a large portion of your database's execution time ......
Read more >How to Make Query Execution Faster in SQL Server
The answer is that SQL Server offers a method to get execution times measured at the millisecond level which is 1000x more precise...
Read more >Troubleshoot a query that shows different performance ...
A query is waiting on a bottleneck if the elapsed time is significantly greater than the CPU time. The elapsed time includes the...
Read more >Why is My Query Faster the Second Time it Runs? (Dear ...
There are more reasons that the second run of a query might be faster. The first time you run the query it may...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hm, I’m not sure. If you can provide some code to run with details instructions so I can reproduce, I can then see where the time is being used.
shoot, no worries will share it through gdrive in .zip archive mode in a day or two !