On Thursday, 19 February 2015 09:01:42 UTC+11, Aria Stewart wrote:
>
>
> > On Feb 18, 2015, at 1:53 PM, Anirban Bhattacharya <
> [email protected] <javascript:>> wrote:
> >
> > This is my node code
> >
> > var http = require('http');
> > var mysql = require('mysql');
> > var connection = mysql.createConnection({
> > host : 'localhost',
> > user : 'root',
> > password: '########'
> > });
> >
>
> This creates a single connection to mySQL for all requests to share, which
> will queue.
>
> > ========================PHP Code===========================
> >
> > <?php
> > mysql_connect("localhost","root","#########");
> > mysql_select_db("test");
>
>
> This creates a new connection to mySQL for each request, and will execute
> in some sort of parallel.
>
>
New connection would be probably even slower than queuing queries
everything in one. It seems that mysql_connect uses connection pool by
default <http://php.net/manual/en/function.mysql-connect.php>:
If a second call is made to mysql_connect() with the same arguments, no new
link will be established, but instead, the link identifier of the already
opened link will be returned.
Also in node you are executing 2 queries for each request - "use test" +
"select * from prod_master". You can just add "database: 'test'" parameter
to `createConnection().
try this version of your code:
var http = require('http');
var mysql = require('mysql');
var connection = mysql.createPool({
host : 'localhost',
user : 'root',
password: '########'
database: 'test'
});
var strQuery = 'select * from prod_master';
http.createServer(function (req, res) {
connection.query( strQuery, function(err, rows){
if(err) {
res.writeHead(502);
return res.end();
}
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(rows));
});
}).listen(9615);
Try to run siege (or ab or wrk) with concurrency > 1 ( say, 100)
Also would be interesting to see performance difference of mysql2 module
compared to mysql (I'm mysql2 author)
--
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/5f3eddb6-3d9a-4ebc-8195-9109afcdf2c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.