NodeJS Test

I did a test to compare which is faster than NodeJS or Apache + PHP?

When I tested the "Hello world" Node application, it was faster, but when I tried to use the http.get function, it was a completely different story.

Why is NodeJS getting so slow? Is this the case at http.get? or what?

Test environment

CPU Intel (R) Core (TM) i5 CPU M 430 @ 2.27GHz
Memory 2927MiB
OS Ubuntu 12.04 LTS
Test Platform Apache Bench
NodeJS v0.8.2
Apache Apache / 2.2.22
PHP PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli)

1. Hello, world application:

NodeJS Code:

var http        = require('http');

http.createServer(function(req, res) {

    res.writeHead(200, {"Content-Type": "text/html"});

    res.end('hello world');    

}).listen(8888);

PHP code:

<?php

    echo "hello world"

?>

Results:

Headline

ab -n 10000 -c 10 hostname .
10,000 requests, 10 concurrent (time in seconds)

NodeJS      1.337   1.361   1.313   1.312   1.329
Apache+PHP  3.923   3.910   3.917   3.926   3.921

ab -n 10000 -c 100

10.000 , 100 ( )

   
NodeJS      1.326   1.369   1.330   1.333   1.459
Apache+PHP  3.933   3.917   3.940   3.908   3.913

ab -n 100000 -c 300

100 000 , 300 ( )

NodeJS      13.560  13.647  13.784  13.807  14.082
Apache+PHP  44.061  41.516  41.523  41.466  41.465

2. :

NodeJS:

var http = require('http');


var options1 = {
          host: 'www.google.com',
          port: 80,
          path: '/',
          method: 'GET'
        };

http.createServer(function (req, res) {


    http.get(options1, function(response) {

        response.on('data', function (chunk) {

        });

        response.on('end', function (chunk) {
            res.writeHead(200, {'Content-Type': 'text/html'});
            res.end('ok');
        });

    });


}).listen(8888);

PHP-:

<?php
    file_get_contents('http://www.google.com');

    echo 'ok';
?>

:

* ab -n 100 -c 10 *

100 , 10 ( )

NodeJS       8.034  8.492   8.619   7.464   7.950
Apache+PHP  18.648  16.699  19.428  17.903  18.297

* ab -n 1000 -c 10 *

1000 , 10 ( )

NodeJS       68.361 74.705  78.473  74.138  66.779
Apache+PHP  150.568 159.024 161.179 160.819 157.605

* ab -n 10000 -c 100 *
10.000 , 100 ( )

NodeJS     1666.988 739.370         
Apache+PHP  310.062 244.485         

* ab -n 10000 -c 50 *
10.000 , 50 ( )

NodeJS      256.096 260.625         
Apache+PHP  149.422 154.422         
+5
1

:

NodeJS:

var http = require('http');

http.globalAgent.maxSockets = 100000;    

var options1 = {
          host: 'www.google.com',
          port: 80,
          path: '/',
          method: 'GET',
          headers: {
              'Connection':'keep-alive'
          }
        };

http.createServer(function (req, res) {


    http.get(options1, function(response) {

        response.on('data', function (chunk) {

        });

        response.on('end', function (chunk) {
            res.writeHead(200, {'Content-Type': 'text/html'});
            res.end('ok');
        });

    });


}).listen(8888);

... . , Apache + PHP .

+2

All Articles