Hi. I am new to node.js I am trying to create a REST service (using
Express) that access data from a SQL Server. I am using mssql module with
Tedious drivers. I created this module:
/*
dbhelper.js
Helper para acceso a base de datos
Victor Espina S
NOI Quality Software, Chile
*/
function dbhelper(params) {
// Properties
this.dbcp = params.dbcp; // DB ConnectionsPool object (created in app.js)
this.config = require("../config");
// Methods
this.runQuery = runQuery;
this.runSP = runSP;
this.getRow = getRow;
this.getScalar = getScalar;
}
// runQuery
// Ejecuta una consulta y devuelve el resultado
//
function runQuery(query) {
var sql = require('mssql');
var dbcp = this.dbcp;
var runSelect = function(pool) {
console.timeEnd("connecting");
return new Promise(function(resolve, reject) {
console.time("request");
var request = new sql.Request(pool);
console.timeEnd("request");
console.time("querying");
request.query(query)
.then(resolve)
.catch(reject);
});
}
var returnResults = function(result) {
console.timeEnd("querying");
return new Promise(function(resolve, reject) {
console.time("closing");
dbcp.close();
console.timeEnd("closing");
resolve(result);
});
}
var resolver = function(resolve, reject) {
try {
console.time("connecting");
dbcp.connect()
.then(runSelect)
.then(returnResults)
.then(resolve)
.catch(reject);
} catch (err) {
reject(err);
}
}
return new Promise(resolver);
}
module.exports = dbhelper;
and this is how I am using it:
function dbTest(req, res, next) {
var dbhelper = require("../modules/dbhelper");
var db = new dbhelper({ dbcp: res.app.locals.dbcp });
db.runQuery("select clave,texto from registro order by clave")
.then(function(result) {
res.send(result);
});
}
Everything works great, but the response times are completely unaceptable:
10s for a 10 rows query!!! Check this image from the node noconsole after
two consecutives requests to the server:
<https://lh3.googleusercontent.com/-oL3nl7XVGJg/WOuTKkNhzHI/AAAAAAAAA20/JkO_M8BxS20fQbuG-DvjmJqm70tYzCfEgCLcB/s1600/Screen%2BShot%2B2017-04-10%2Bat%2B10.56.29%2BAM.png>
Any ideas about what may be going on ? I tried this same query from a
client app and it takes less than 1s. I am running node.js under OSX and
the SQL Server (2016) is running under a virtualized Windows Server 2016,
running in the same osx machine.
Victor
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/233108be-6214-45da-bb63-7f038910ba4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.