Thursday, 15 April 2010

javascript - Node-Mysql database query + res.json far too slow -



javascript - Node-Mysql database query + res.json far too slow -

i learning node.

using express , node-mysql, able query mysql database , homecoming result client json.

however, far slow. simple query limit of 100 taking 6 seconds response.

according logger, db query takes 8 ms run - not think node-mysql problem.

but other thing doing passing resultset response object converted json.

here code, roughly:

route:

app.get( "/exercises", function( req, res ){ exercises.get( req.query, function( result ){ res.json( result ); }); });

model:

module.exports.get = function( params, cb ){ var sql = "select * exercises limit 100"; db.do( sql, function( result ){ var response = {}; response.data = result[ 0 ]; response.meta = result[ 1 ][ 0 ]; cb( response ); }); };

db:

module.exports.do = function( sql, vals, cb ){ var selectstart = +new date(); pool.acquire(function( err, db ){ db.query( sql, vals, function( err, result ) { cb( result ); console.log( "query execuction: %d ms", +new date() - selectstart ); pool.release( db ); }); }); };

does know doing wrong / why taking long send resultset client?

thanks (in advance) help.

i'm not familiar pool, , unfortunately can't comment yet. 1 thing noticed calling db.do 2 arguments, while takes three. should raise 'undefined not function' when seek callback.

javascript node.js node-mysql

No comments:

Post a Comment