PHP vs Node.js vs Nginx-Lua

2013-01-04/emptyhua@gmail.com

ENV

Server

Red Hat Enterprise Linux Server release 6.2 (Santiago)
CPU:Intel(R) Xeon(R) X5680 3.33GHz X 24
MEM:24G

Client

Red Hat Enterprise Linux Server release 6.2 (Santiago)
CPU:AMD Opteron(tm) Processor 4280 X 16
MEM:32G

Software

openresty 1.2.4.14
PHP 5.3.6
node.js v0.8.16
ab 2.3 

Scripts

hello.php

<?php
echo "hello world\n";
?>

bench.hello.js

var http = require('http');

function server_start() {
    http.createServer(function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end('hello world\n');
    }).listen(8080);
}


var cluster = require('cluster');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
    for (var i = 0; i < numCPUs; i++) {
        cluster.fork();
    }
} else {
    server_start();
}

nginx.conf

location /lua_hello {
    content_by_lua '
        ngx.say("hello world")
    ';
}

Commands

curl "http://192.168.99.93:9999/start?group=php.node.lua&name=php-fpm&pgrep=php-fpm,worker%20process&iface=eth1/out"
sleep 6
ab -n 10000000 -c 100 http://192.168.99.93/hello.php
curl "http://192.168.99.93:9999/stop?group=php.node.lua&name=php-fpm"

curl "http://192.168.99.93:9999/start?group=php.node.lua&name=node.js&pgrep=bench.hello.js&iface=eth1/out"
sleep 6
ab -n 10000000 -c 100 http://192.168.99.93:8080/get
curl "http://192.168.99.93:9999/stop?group=php.node.lua&name=node.js"

curl "http://192.168.99.93:9999/start?group=php.node.lua&name=nginx-lua&pgrep=worker%20process&iface=eth1/out"
sleep 6
ab -n 10000000 -c 100 http://192.168.99.93/lua_hello
curl "http://192.168.99.93:9999/stop?group=php.node.lua&name=nginx-lua"

Results

PHP

Server Software: ngx_openresty/1.2.4.14
Server Hostname: 192.168.99.93
Server Port: 80

Document Path: /hello.php
Document Length: 12 bytes

Concurrency Level: 100
Time taken for tests: 574.692 seconds
Complete requests: 10000000
Failed requests: 0
Write errors: 0
Total transferred: 1690000676 bytes
HTML transferred: 120000048 bytes
Requests per second: 17400.61 [#/sec] (mean)
Time per request: 5.747 [ms] (mean)
Time per request: 0.057 [ms] (mean, across all concurrent requests)
Transfer rate: 2871.78 [Kbytes/sec] received

Connection Times (ms)
              min mean[+/-sd] median max
Connect: 0 1 0.9 1 6
Processing: 0 4 1.9 4 125
Waiting: 0 4 1.7 4 124
Total: 0 6 2.0 6 127

Percentage of the requests served within a certain time (ms)
  50% 6
  66% 6
  75% 7
  80% 7
  90% 8
  95% 9
  98% 11
  99% 11
 100% 127 (longest request)

Node.js

Server Software:        
Server Hostname: 192.168.99.93
Server Port: 8080

Document Path: /get
Document Length: 12 bytes

Concurrency Level: 100
Time taken for tests: 320.541 seconds
Complete requests: 10000000
Failed requests: 0
Write errors: 0
Total transferred: 1130001017 bytes
HTML transferred: 120000108 bytes
Requests per second: 31197.23 [#/sec] (mean)
Time per request: 3.205 [ms] (mean)
Time per request: 0.032 [ms] (mean, across all concurrent requests)
Transfer rate: 3442.67 [Kbytes/sec] received

Connection Times (ms)
              min mean[+/-sd] median max
Connect: 0 2 59.7 1 9001
Processing: 0 1 3.8 1 610
Waiting: 0 1 3.8 1 610
Total: 0 3 59.8 2 9002

Percentage of the requests served within a certain time (ms)
  50% 2
  66% 2
  75% 2
  80% 2
  90% 3
  95% 3
  98% 3
  99% 4
 100% 9002 (longest request)

Nginx-Lua

Server Software: ngx_openresty/1.2.4.14
Server Hostname: 192.168.99.93
Server Port: 80

Document Path: /lua_hello
Document Length: 12 bytes

Concurrency Level: 100
Time taken for tests: 306.482 seconds
Complete requests: 10000000
Failed requests: 0
Write errors: 0
Total transferred: 1790002864 bytes
HTML transferred: 120000192 bytes
Requests per second: 32628.32 [#/sec] (mean)
Time per request: 3.065 [ms] (mean)
Time per request: 0.031 [ms] (mean, across all concurrent requests)
Transfer rate: 5703.59 [Kbytes/sec] received

Connection Times (ms)
              min mean[+/-sd] median max
Connect: 0 1 2.1 1 3001
Processing: 1 2 0.6 2 98
Waiting: 0 1 0.6 1 98
Total: 1 3 2.2 3 3003

Percentage of the requests served within a certain time (ms)
  50% 3
  66% 3
  75% 3
  80% 3
  90% 3
  95% 3
  98% 3
  99% 4
 100% 3003 (longest request)

System load