Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS benchmark [closed]

I've made benchmark, to compare what is faster NodeJS or Apache + PHP?

When I had tested 'Hello world' application Node was faster, but when I tried to use http.get function It was completely different story.

Why NodeJS is becoming so slow? Is it deal in 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:

Heading

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 hostname

10.000 requests, 100 concurrent (time in seconds)

   
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 hostname

100.000 requests, 300 concurrent (time in seconds)

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

2. Pull feeds application:

NodeJS code:

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 code:

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

    echo 'ok';
?>

Results:

*ab -n 100 -c 10 hostname *

100 requests, 10 concurrent (time in seconds)

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 hostname *

1000 requests, 10 concurrent (time in seconds)

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 hostname *
10.000 requests, 100 concurrent (time in seconds)

NodeJS     1666.988 739.370         
Apache+PHP  310.062 244.485         

*ab -n 10000 -c 50 hostname *
10.000 requests, 50 concurrent (time in seconds)

NodeJS      256.096 260.625         
Apache+PHP  149.422 154.422         
like image 319
Pavel Lapin Avatar asked Nov 03 '22 05:11

Pavel Lapin


1 Answers

I've changed my code to:

NodeJS code:

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);

But... It didn't change much. It got a little bit faster but in compare with Apache+PHP it is very slow.

like image 108
Pavel Lapin Avatar answered Nov 11 '22 04:11

Pavel Lapin