Interesting. Your PHP code is still just: mysql_connect("localhost","root","XXXXX@");
Which, I believe, will open a separate connection to the mysql server for each PHP process in the process pool. Speaking of which, we don't know if you're using mod_php here, in which case you have as many distinct PHP processes as you have Apache processes (a number that grows to a limit set in your Apache configuration), or if you're using fcgi, or... etc. But since it hasn't come up, you're probably using mod_php. Which means you probably have... 32? 64? Something on that order... simultaneous PHP processes, and that number of simultaneous connections to MySQL. Meanwhile, in node, you're opening *one* connection to MySQL, and you're reusing it for all the requests that come in. Which is a perfectly sane and sensible thing to do, since beating the crap out of the MySQL server isn't necessarily a good thing. But, the optimal number of queries in progress at once probably isn't 1. It's probably somewhat bigger than 1. Which is why Node is initially slower than MySQL. So to do a more representative test, you need to use connection pooling in node's mysql module, and give mysql permission to open as many simultaneous connections as PHP is implicitly opening. Check out the pooling section in the mysql module documentation which is straightforward: https://github.com/felixge/node-mysql/#install In particular: var mysql = require('mysql'); var pool = mysql.createPool({ connectionLimit : 10, host : 'example.org', user : 'bob', password : 'secret' }); pool.query('SELECT 1 + 1 AS solution', function(err, rows, fields) { if (err) throw err; console.log('The solution is: ', rows[0].solution); }); That opens up to 10 connections at a time. To match PHP's behavior you will have to dig through your apache configuration to find out how many Apache processes are allowed to run at one time (assuming you're using mod_php, which you probably are). Or you could use something like "ps auxw | grep apache | wc -l" to count them during the peak load of your test run. Otherwise... still not apples to apples (: On Fri, Feb 27, 2015 at 5:35 PM, Anirban Bhattacharya <anirbanbhattacharya1...@gmail.com> wrote: > Here is Git link for source codes and database structure > > https://github.com/anisoftcorporation/nodevsphp > > > On Wednesday, February 18, 2015 at 3:34:57 PM UTC-6, Anirban Bhattacharya > wrote: >> >> Hi, >> I am new to node. very new ..like infant. >> Either I am doing something wrong or I understood everything wrong. >> I wrote a node js simple JSON emitter which uses mysql module and query >> (select *) from a single table haviing 100 records and outputs on page as >> JSON (JSON.stringify.. >> >> I wrote a PHP page which also does the same thing from same table(Apache). >> >> I used Siege for load test and surprisingly it shows better values for the >> PHP than that of node .. see below the output of siege >> ==================NODE================= >> anirbanb2004@Anisoft-Corporation:~$ siege -c100 -d1 -t10M -lnode.log >> http://localhost:9615/ >> ** SIEGE 3.0.5 >> ** Preparing 100 concurrent users for battle. >> The server is now under siege... >> Lifting the server siege... done. >> >> Transactions: 119236 hits >> Availability: 100.00 % >> Elapsed time: 599.74 secs >> Data transferred: 403.00 MB >> Response time: 0.00 secs >> Transaction rate: 198.81 trans/sec >> Throughput: 0.67 MB/sec >> Concurrency: 0.61 >> Successful transactions: 119236 >> Failed transactions: 0 >> Longest transaction: 0.05 >> Shortest transaction: 0.00 >> >> FILE: node.log >> =================PHP================== >> anirbanb2004@Anisoft-Corporation:~$ siege -c100 -d1 -t10M -lphp.log >> http://localhost/loadTest >> ** SIEGE 3.0.5 >> ** Preparing 100 concurrent users for battle. >> The server is now under siege... >> Lifting the server siege... done. >> >> Transactions: 119632 hits >> Availability: 100.00 % >> Elapsed time: 599.47 secs >> Data transferred: 34.58 MB >> Response time: 0.00 secs >> Transaction rate: 199.56 trans/sec >> Throughput: 0.06 MB/sec >> Concurrency: 0.12 >> Successful transactions: 59858 >> Failed transactions: 0 >> Longest transaction: 0.03 >> Shortest transaction: 0.00 >> >> FILE: php.log >> >> can anyone please help me understand what is wrong here? I understand some >> scenario will be there where PHP will perform better. What scenario should I >> create to test Node is better? > > -- > 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 a topic in the > Google Groups "nodejs" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/nodejs/mf0Qhj1WVl8/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > nodejs+unsubscr...@googlegroups.com. > To post to this group, send email to nodejs@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/nodejs/b8ce6d14-bb08-4cc0-860d-e54f593ee133%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- THOMAS BOUTELL, DEV & OPS P'UNK AVENUE | (215) 755-1330 | punkave.com -- 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 nodejs+unsubscr...@googlegroups.com. To post to this group, send email to nodejs@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAORXhGJN39SQi%2Bda8QAas3OmyPhEW0CuYhkmUaqUEdfPYbUXTg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.