Why siege test showing PHP is performing better than Node

673 views
Skip to first unread message

Anirban Bhattacharya

unread,
Feb 18, 2015, 4:34:57 PM2/18/15
to nod...@googlegroups.com, Anirban Bhattacharya
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?

Aria Stewart

unread,
Feb 18, 2015, 4:50:19 PM2/18/15
to nod...@googlegroups.com, Anirban Bhattacharya
On Feb 18, 2015, at 1:34 PM, Anirban Bhattacharya <anirbanbhat...@gmail.com> 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).


It looks like node is transferring a lot more data- - sounds like this is not an apples to apples comparison.

What kind of concurrency do you have on talking to mySQL?

Actual scripts would be easier to compare. Without seeing what you've written, it's hard to say why what's faster is faster.

Aria


--
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+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/b4db83d5-7fe9-4c5e-b87c-9c7c852a0e33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anirban Bhattacharya

unread,
Feb 18, 2015, 4:53:17 PM2/18/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
This is my node code

var http = require('http');
var mysql = require('mysql');
var connection =  mysql.createConnection({
      host : 'localhost',
      user : 'root',
      password: '########'
  });


 connection.connect(function (err){
if(err){
console.log('error!!!'+err.stack);
return;
}

console.log('connected..');
});
http.createServer(function (req, res) {
 

connection.query('use test');

  var strQuery = 'select * from prod_master';   
 
  connection.query( strQuery, function(err, rows){
      if(err)    {
          throw err;
      }else{
 res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(JSON.stringify(rows));         

      }

  });

}).listen(9615);

========================PHP Code===========================

<?php
mysql_connect("localhost","root","#########");
mysql_select_db("test");

$result=mysql_query("select * from prod_master");
$row = array();
while($r=mysql_fetch_assoc($result))
{
 $row[] = $r;
}

echo json_encode($row);
?>

Aria Stewart

unread,
Feb 18, 2015, 5:01:42 PM2/18/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in

> On Feb 18, 2015, at 1:53 PM, Anirban Bhattacharya <anirbanbhat...@gmail.com> 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.

That should explain some difference.

Alexej Yaroshevich

unread,
Feb 18, 2015, 10:29:17 PM2/18/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
Where you see better stats for PHP?

Successful transactions 59858/119632 — PHP even can't resolve all transactions
Throughput:                0.06 MB/sec vs Throughput:                0.67 MB/sec — Node 10x "faster"

Also I can say that this siege test is pretty strange. Anyway, you'll never get a PHP faster than Node just because Node is asynchronous and non-blocking. While PHP (apache of fpm) making threads, executing code and shutting them Node just waiting for data, melting it, and pushing it back.

Andrey

unread,
Feb 18, 2015, 10:33:58 PM2/18/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
New connection would be probably even slower than queuing queries everything in one. It seems that mysql_connect uses connection pool by default

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)

Anirban Bhattacharya

unread,
Feb 19, 2015, 12:44:16 PM2/19/15
to nod...@googlegroups.com
Thanks a lot...any suggestion to modify the node code of mysql connection...where to move it so that it works the same way as of the PHP code?

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+un...@googlegroups.com.

To post to this group, send email to nod...@googlegroups.com.

Anirban Bhattacharya

unread,
Feb 20, 2015, 2:29:16 PM2/20/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
So,

I made changes to code of node.

1. I removed that extra query for use data base and added in connect paarmeter.
2. I changed it to createPool. But still the siege output is awkward

See in node (the upper one)
1. The number of hits and transactions is less than that of PHP+Apache
 in node it is 119171 and for php+apache it is 119429
2. Longest transaction is more in node than PHP


Why is so? What will be a good basic scenario which can show me NODe has better values for these

====================================================After Doing pool==============================================
anirbanb2004@Anisoft-Corporation:~/nodecode/express/siegeLog$ 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:              119171 hits
Availability:              100.00 %
Elapsed time:              599.32 secs
Data transferred:          402.78 MB

Response time:                0.00 secs
Transaction rate:          198.84 trans/sec
Throughput:                0.67 MB/sec
Concurrency:                0.67
Successful transactions:      119171
Failed transactions:               0
Longest transaction:            0.10

Shortest transaction:            0.00
 
FILE: node.log

anirbanb2004@Anisoft-Corporation:~/nodecode/express/siegeLog$ 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:              119429 hits
Availability:              100.00 %
Elapsed time:              599.04 secs
Data transferred:           58.77 MB
Response time:                0.00 secs
Transaction rate:          199.37 trans/sec
Throughput:                0.10 MB/sec
Concurrency:                0.36
Successful transactions:      119429
Failed transactions:               0
Longest transaction:            0.04

Shortest transaction:            0.00
 
FILE: php.log


Andrey

unread,
Feb 20, 2015, 6:51:34 PM2/20/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
Are you sure you have 100 rows in your prod_master? try to replace query with "select * from prod_master limit 100"
200 rps seems to be too low for 100 rows of data

Anirban Bhattacharya

unread,
Feb 20, 2015, 10:43:17 PM2/20/15
to nod...@googlegroups.com
Hi yes,
As per throughput node is 6.7 times more than of php as of the above result.
But i am still surely not sure why transfer rate so clow. Aslo if no failure then what does the meaning of less data transferred in PHP?
I will double check my node output to make sure that its non repeating output.

By the way when I ran same for concurrency 500 delay 1 sec and for 10mins node ran just fine but after few transaction PHP requests failed.

I will capture that record and share soon.

Daniel Rinehart

unread,
Feb 21, 2015, 1:12:19 AM2/21/15
to nodejs, anirbanbhat...@yahoo.co.in
I've not looked at the code but the the two tests still don't look identical given that node transferred 402MB to PHP's 58MB which is reflected in node's almost 7x throughput, which I'd count as a resounding success :) Yet another reason I distrust microbenchmarks like this one.

--
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+un...@googlegroups.com.

To post to this group, send email to nod...@googlegroups.com.

Matt

unread,
Feb 21, 2015, 1:12:46 AM2/21/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
So Node transferred 400MB of data in the same time that PHP transferred 58MB of data? Sounds like a big win for Node.

On Fri, Feb 20, 2015 at 2:29 PM, Anirban Bhattacharya <anirbanbhat...@gmail.com> wrote:

--
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+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.

Anirban Bhattacharya

unread,
Feb 21, 2015, 1:13:58 AM2/21/15
to nod...@googlegroups.com, Anirban Bhattacharya

I am going to perform with 500 concurrent now with 1 sec delay for 10 mins and see if that makes difference.

--
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+un...@googlegroups.com.

Ryan Schmidt

unread,
Feb 21, 2015, 1:14:36 AM2/21/15
to nod...@googlegroups.com, Anirban Bhattacharya, anirbanbhat...@yahoo.co.in
Why did PHP transfer so much less data than Node in your tests?

Tom Boutell

unread,
Feb 21, 2015, 7:46:30 AM2/21/15
to nod...@googlegroups.com
This code is asking mysql to do a lot of work and then doing almost no work in node or PHP.

In such a scenario both programs will get tweaked until they run the optimal number of simultaneous mysql queries on this particular server, whatever that is- but it will teach you nothing about node versus PHP.

The application is "database-bound."

Anirban Bhattacharya

unread,
Feb 21, 2015, 3:57:33 PM2/21/15
to nod...@googlegroups.com

Seriously? A just select query is considered as so much db operation for a web app?
Ok tell me how to create test scenario ? A hello world will do?

--
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+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.

Tom Boutell

unread,
Feb 21, 2015, 5:05:56 PM2/21/15
to nod...@googlegroups.com
On Feb 21, 2015 3:57 PM, "Anirban Bhattacharya" <anirbanbhat...@gmail.com> wrote:

Seriously? A just select query is considered as so much db operation for a web app?
Ok tell me how to create test scenario ? A hello world will do?

I'm not sure you understand what I'm saying.

In your scenario, only one thing is really doing any work. And that thing is the database.

So it does not matter very much which language you choose, from a strictly performance standpoint.

But to put it another way...

Hello World "benchmarks" are meaningless. One-query database "benchmarks" are also meaningless. They have nothing to do with real work. They don't measure anything important.

Write a quick prototype of the real-world application you are interested in building - a half-complete version, just one important feature - just enough to test a real-world scenario that actually matters.

Write it in both languages, both frameworks.

Then measure:

The time it takes you to do it
How much you enjoy working with it
How hard it is to read the resulting code
How hard it is to maintain the resulting code
*And* the performance.

Decide what the "sweet spot" is for all five of those metrics for your particular project's needs, and make the right choice for you.

You will never find the "perfect benchmark" that tells you which tool is better. A screwdriver is not better than a hammer.

--
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+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.

Anirban Bhattacharya

unread,
Feb 21, 2015, 8:34:11 PM2/21/15
to nod...@googlegroups.com

I must say indeed a realistic method than just let a tool decide. loved it.

Anirban Bhattacharya

unread,
Feb 25, 2015, 9:55:11 AM2/25/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
Now when I am running Siege (a load test utility that simulate automatic requests to websites) I get the below data

When it is hitting node application

HTTP/1.1 200   0.00 secs:    3544 bytes ==> GET  /

And when It is hitting PHP it is

HTTP/1.1 200   0.06 secs:     516 bytes ==> GET  /loadTest/PHP/

When I do open in browser both the output looks same, for PHP the font looks bigger (not sure how this differs).


Below are complete codes..but no idea why each request to node giving more data than that of PHP+Apache


var http = require('http');
var mysql = require('mysql');
var connection =  mysql.createConnection({
      host
: 'localhost',
      user
: 'root',

      password
: 'XXXXX',
    database
: 'test'
 
});

http
.createServer(function (req, res) {

var strQuery = 'select * from prod_master';
   
connection
.query( strQuery, function(err, rows){

res
.writeHead(200, {'Content-Type': 'text/plain'});
res
.end(JSON.stringify(rows));          
});
}).listen(9615);Enter code here...
Below is my PHP code
<?php
mysql_connect
("localhost","root","XXXXXX");

mysql_select_db
("test");

$result
=mysql_query("select * from prod_master");
$row
= array();
while($r=mysql_fetch_assoc($result))
{
 $row
[] = $r;
}

echo json_encode
($row);
?>


Any idea why the data from GET to node is so much for than that of PHP?






On Wednesday, February 18, 2015 at 3:34:57 PM UTC-6, Anirban Bhattacharya wrote:

Aria Stewart

unread,
Feb 25, 2015, 10:25:23 AM2/25/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in

> On Feb 25, 2015, at 3:01 AM, Anirban Bhattacharya <anirbanbhat...@gmail.com> wrote:
>
> Now when I am running Siege (a load test utility that simulate automatic requests to websites) I get the below data
>
> When it is hitting node application
>
> HTTP/1.1 200 0.00 secs: 3544 bytes ==> GET /
>
> And when It is hitting PHP it is
>
> HTTP/1.1 200 0.06 secs: 516 bytes ==> GET /loadTest/PHP/
>
> When I do open in browser both the output looks same, for PHP the font looks bigger (not sure how this differs).
>
>
> Below are complete codes..but no idea why each request to node giving more data than that of PHP+Apache


try curl -v on each URL, save the output, and compare with diff -u. You should be able to spot what's different about them.

At least the content-type differs, but you've got 3kb of data unaccounted for too.

Alex Yaroshevich

unread,
Feb 25, 2015, 10:25:45 AM2/25/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
Because PHP doesn't work ;-)

Can you manually make some requests to PHP and Node and look at results?

Call these (after you've start your node and apache+php):
curl -v http://localhost:9615/

curl -v http://localhost/loadTest/PHP
/

Anirban Bhattacharya пишет:
--
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+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
A. Yaroshevich
+7 926 543-4548

Anirban Bhattacharya

unread,
Feb 25, 2015, 5:25:33 PM2/25/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
I was wrong...thanks Aria and Alex for directing me to correct direction..the JSON outputs were different.

PHP was not trimming of double quotes around integer values by default..I had PROD_ID as integer.

Also the content length for PHP was showing less for chunked transfer encoding. I must set content type application_json and content length.

Added below lines /modified in my PHP then the output became similar . diff -s said identical.

Also siege with verbose showed content length/size same

$data = json_encode($row,JSON_NUMERIC_CHECK);
header
('Content-Length:'.strlen($data));
header
("Content-Type:application/json");
echo
($data);

Now I am going to re-run the whole test again


On Wednesday, February 18, 2015 at 3:34:57 PM UTC-6, Anirban Bhattacharya wrote:

Anirban Bhattacharya

unread,
Feb 26, 2015, 10:05:58 AM2/26/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
These are my final results

When ran 500 concurrent users for 10 minutes PHP performed well...but when I did test with 15 minutes long PHP failed. But node js survived.
============================================ Running for 10 Minutes =====================================================

anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t10M -lnode1.log http://localhost:9615
** SIEGE 3.0.5
** Preparing 500 concurrent users for battle.

The server is now under siege...
Lifting the server siege...      done.

Transactions:              594697 hits
Availability:              100.00 %
Elapsed time:              599.95 secs
Data transferred:         1666.28 MB
Response time:                0.00 secs
Transaction rate:          991.24 trans/sec
Throughput:                2.78 MB/sec
Concurrency:                3.84
Successful transactions:      594697
Failed transactions:               0
Longest transaction:            0.20
Shortest transaction:            0.00
 
FILE: node1.log

anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t10M -lnphp1.log http://localhost/loadTest/PHP/
** SIEGE 3.0.5
** Preparing 500 concurrent users for battle.

The server is now under siege...
Lifting the server siege...      done.

Transactions:              597276 hits
Availability:              100.00 %
Elapsed time:              599.97 secs
Data transferred:         1673.50 MB
Response time:                0.00 secs
Transaction rate:          995.51 trans/sec
Throughput:                2.79 MB/sec
Concurrency:                1.94
Successful transactions:      597276
Failed transactions:               0
Longest transaction:            0.20
Shortest transaction:            0.00
 
FILE: nphp1.log

======================================================15 Minutes========================================================

anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t15M -lnode1.log http://localhost:9615
** SIEGE 3.0.5
** Preparing 500 concurrent users for battle.

The server is now under siege...
Lifting the server siege...      done.

Transactions:              892874 hits
Availability:              100.00 %
Elapsed time:              899.25 secs
Data transferred:         2501.74 MB
Response time:                0.00 secs
Transaction rate:          992.91 trans/sec
Throughput:                2.78 MB/sec
Concurrency:                3.74
Successful transactions:      892874
Failed transactions:               0
Longest transaction:            0.25
Shortest transaction:            0.00
 
FILE: node1.log

anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t15M -lnphp1.log http://localhost/loadTest/PHP/
** SIEGE 3.0.5
** Preparing 500 concurrent users for battle.

The server is now under siege...

[error] socket: 1011885824 address is unavailable.: Cannot assign requested address
[error] socket: -213448960 address is unavailable.: Cannot assign requested address
[error] socket: -3631360 address is unavailable.: Cannot assign requested address


Lifting the server siege...      done.

Transactions:              893948 hits
Availability:               99.96 %
Elapsed time:              899.70 secs
Data transferred:         2504.75 MB
Response time:                0.00 secs
Transaction rate:          993.61 trans/sec
Throughput:                2.78 MB/sec
Concurrency:                2.25
Successful transactions:      893948
Failed transactions:             335
Longest transaction:            1.01
Shortest transaction:            0.00
 
FILE: nphp1.log



On Wednesday, February 18, 2015 at 3:34:57 PM UTC-6, Anirban Bhattacharya wrote:

Anirban Bhattacharya

unread,
Feb 26, 2015, 10:07:31 AM2/26/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
And when I ran for 1000 concurrent users for 10 minutes I can see the huge difference in concurrency for Node

=======================================1K concurrent for 10 minutes ==============================
anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c1000 -d1 -t10M -lnode1.log http://localhost:9615
** SIEGE 3.0.5
** Preparing 1000 concurrent users for battle.

The server is now under siege...
Lifting the server siege...      done.

Transactions:              862079 hits
Availability:              100.00 %
Elapsed time:              599.92 secs
Data transferred:         2415.46 MB
Response time:                0.20 secs
Transaction rate:         1436.99 trans/sec
Throughput:                4.03 MB/sec
Concurrency:              281.62
Successful transactions:      862079
Failed transactions:               0
Longest transaction:            0.55

Shortest transaction:            0.00
 
FILE: node1.log


anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c1000 -d1 -t10M -lnphp1.log http://localhost/loadTest/PHP/
** SIEGE 3.0.5
** Preparing 1000 concurrent users for battle.

The server is now under siege...
Lifting the server siege...      done.

Transactions:             1193412 hits
Availability:              100.00 %
Elapsed time:              599.82 secs
Data transferred:         3343.82 MB
Response time:                0.00 secs
Transaction rate:         1989.62 trans/sec
Throughput:                5.57 MB/sec
Concurrency:                5.58
Successful transactions:     1193412
Failed transactions:               0
Longest transaction:            0.54

Shortest transaction:            0.00
 
FILE: nphp1.log



On Wednesday, February 18, 2015 at 3:34:57 PM UTC-6, Anirban Bhattacharya wrote:

Tom Boutell

unread,
Feb 26, 2015, 10:18:22 AM2/26/15
to nod...@googlegroups.com
Thanks for sharing these results. When posting benchmarks please
always include gist links or similar with the source code of the
benchmarks concerned.

Although I prefer Node, I have a hunch that this still wasn't really
apples to apples comparison, in terms of how PHP and Node were each
configured to open connections to MySQL or reuse them.
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/cf93b58d-37d5-4eb1-8354-44b5589f8198%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--


THOMAS BOUTELL, DEV & OPS
P'UNK AVENUE | (215) 755-1330 | punkave.com

Anirban Bhattacharya

unread,
Feb 26, 2015, 12:07:13 PM2/26/15
to nod...@googlegroups.com
Tom,
True.Specially when avoiding this chunked transfer encoding in php i felt of ripping off one of (php apache) 's feature. Nuzt to make everything similar had to tweek. But though not apple to apple , its not apple to orange either. Lets call this apple to pears :).

I will share git hub link today. Yet to push latest changes.

Anirban Bhattacharya

unread,
Feb 27, 2015, 9:50:43 PM2/27/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
Here is Git link for source codes and database structure

Tom Boutell

unread,
Feb 27, 2015, 10:51:40 PM2/27/15
to nod...@googlegroups.com
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 (:
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/b8ce6d14-bb08-4cc0-860d-e54f593ee133%40googlegroups.com.

Anirban Bhattacharya

unread,
Feb 28, 2015, 5:24:17 PM2/28/15
to nod...@googlegroups.com
Tom,
Thanks for taking yourbtime going through the code.
I did add connection.createPool as you suggested when I startes this post. But didn't see much difference so removed.

You are right i mixed up my two thkughts in one i tried to test with default of both, in other i was assuming they are having similar configuration.

So the failures in apache for 15 mins run is probably due to Apache started rejecting new proccesses as anymore proceas could maxout runtime memory.

I didn't understand the point you said the query size is greater than 1 in node. What is that?

Yes I may do pool in both and see again.

Matt

unread,
Feb 28, 2015, 6:13:09 PM2/28/15
to nod...@googlegroups.com
On Fri, Feb 27, 2015 at 5:35 PM, Anirban Bhattacharya <anirbanbhat...@gmail.com> wrote:
Here is Git link for source codes and database structure


You're only using one CPU for node here, which massively disadvantages it.. You need to use cluster.

Andrey

unread,
Feb 28, 2015, 6:41:26 PM2/28/15
to nod...@googlegroups.com
I'll outline some difference between your php and node implementation and share my results

1) Apache runs multiple workers / threads. You'll need to use cluster in your node script to match this.
2) mysql_connect in php does implicit connection pooling. Use "createPool()" in node script

My results using cluster/pool  and wrk as load generator ( "wrk -t 10 -c 100 -d 100s http://localhost:9615/" ) - 

php ~500 resp/sec
node ~3000 resp/sec

Tom Boutell

unread,
Feb 28, 2015, 10:15:30 PM2/28/15
to nod...@googlegroups.com
I want to dispute Andrey's first point but... I don't disagree so much
as I gotta point out that they are just fundamentally different.

Unless you find an asynchronous version of the mysql library for PHP,
and rewrite your PHP code using reactphp.org's stuff plus that
asynchronous version of the mysql library for PHP... it's not going to
act all that much like node.

But yes, there might be some case where most of the work is in the
actual string-crunching in the node/php code, and in that case, you'd
need something like the cluster module to match what PHP does
automatically (but without much finesse).
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/1acca32e-9ec8-4842-b419-e4fbf33dd2f5%40googlegroups.com.

Alexey Petrushin

unread,
Mar 1, 2015, 10:13:12 AM3/1/15
to nod...@googlegroups.com, anirbanbhat...@yahoo.co.in
Also, if you are interested in "kinda real-life" Node.js benchmarks, here's one more for Ruby on Rails vs Node.js


3782 (node.js) vs. 2914 (ruby on rails) hits

Matt

unread,
Mar 2, 2015, 11:47:32 AM3/2/15
to nod...@googlegroups.com, Anirban Bhattacharya
That Node vs Rails benchmark is also broken for almost exactly the same reasons your benchmark is broken: It doesn't use cluster, and it uses the default Node.js "Agents" limitation on outgoing HTTP requests (which will only do 5 in parallel).

You want a real-world example? I ported a Rails application to Node.js and it got significantly faster. A real full-blown app. Everything felt faster to our users. That's the only benchmark that matters. I did benchmark some endpoints and they went from around 100rps to around 1000rps, but just testing one endpoint doesn't really matter - you need to get a feel for the entire app.

Matt.

--
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+un...@googlegroups.com.

To post to this group, send email to nod...@googlegroups.com.

Axel Kittenberger

unread,
Mar 3, 2015, 11:46:14 AM3/3/15
to nodejs, Anirban Bhattacharya
However, comparing naive approaches with different utilities like these does have its warrant. Lets please not ignore that. Technically it may be apples vs. oranges but from a user perspective it is not. It is comparing how well you App does after you spend say an afternoon or weekend getting comfortable with either toolchain and doing your thing.

After all this is what users wanting to concentrate on inventing something often do. They don't want to spend their time on complicated issues to squeeze out the last bit, they just get these basic things done as fast as possible while making their inventive contribution on the plane on it.

And if a naive 2 liner in php performs better unless you someone tells you, you gotta use a pool module and you gotta use a cluster module and and and in node, this is also a statement for both toolchains.

After all, this is what both tool chains are about first place compared to doing a heavy C(++) implementation, getting things developed rapidly. And even with that, you'd also have to fine tune the native thing a lot, like using hashtables, while using either PHP or Node you get them free of the box, thus you might perform better than using a naive C++ application.


Louis Santillan

unread,
Mar 3, 2015, 11:46:40 AM3/3/15
to nod...@googlegroups.com, Anirban Bhattacharya

Matt

unread,
Mar 3, 2015, 12:58:48 PM3/3/15
to nod...@googlegroups.com

On Tue, Mar 3, 2015 at 1:32 AM, Axel Kittenberger <axk...@gmail.com> wrote:
However, comparing naive approaches with different utilities like these does have its warrant. Lets please not ignore that. Technically it may be apples vs. oranges but from a user perspective it is not. It is comparing how well you App does after you spend say an afternoon or weekend getting comfortable with either toolchain and doing your thing.

I'm sorry, no I don't buy that. The original poster has categorically not got comfortable with the toolchain. He's been repeatedly told why his test is bogus, and being comfortable requires understanding why EVERY production installation of Node uses cluster and database connection pooling. There's no comfort with the toolchain whatsoever. There are better benchmarks out there such as the TechEmpower ones, and even those are fairly flawed in various ways.

Reply all
Reply to author
Forward
0 new messages