question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why is query execution time so high ?

See original GitHub issue

Why 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 mysql

Also for native driver execution time, please see below attached screenshot:

native driver

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:closed
  • Created 6 years ago
  • Comments:21 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
dougwilsoncommented, Apr 23, 2017

Another aspect which i have observed when query execution after idle time it takes more time , then after it executes like seamlessly any pointers.

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.

plus config of your machine and OS ?

image

0reactions
matt212commented, Apr 23, 2017

shoot, no worries will share it through gdrive in .zip archive mode in a day or two !

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found