Why is the query execution time so long for the Mysql Native driver for node.js? Any alternatives?

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.

Running Workbench Mysql

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

enter image description here

Codebase for node.js Mysql Native driver

db.js

var mysql = require('mysql');
var connectionpool = mysql.createPool({
    connectionLimit: 100, //important
    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();
                    // calculate the duration in seconds
                    var duration = (post_query - pre_query) / 1000;
                    console.log(duration)
                        // console.log(red);
                    res.json(red);

                }
            })
        })
+4
source share
1 answer

JS . , MySQL Workbench ( MySQL), - , ( ). , 300 . init pre_query . ( console.log(err). , .

+1

Source: https://habr.com/ru/post/1675416/


All Articles