Node.js slower than Apache

前端 未结 6 901
误落风尘
误落风尘 2020-12-13 10:25

I am comparing performance of Node.js (0.5.1-pre) vs Apache (2.2.17) for a very simple scenario - serving a text file.

Here\'s the code I use for node server:

<
6条回答
  •  自闭症患者
    2020-12-13 11:00

    $ cat /var/www/test.php
    
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking localhost (be patient)
    Completed 10000 requests
    Completed 20000 requests
    Completed 30000 requests
    Completed 40000 requests
    Completed 50000 requests
    Completed 60000 requests
    Completed 70000 requests
    Completed 80000 requests
    Completed 90000 requests
    Completed 100000 requests
    Finished 100000 requests
    
    
    Server Software:        Apache/2.2.17
    Server Hostname:        localhost
    Server Port:            80
    
    Document Path:          /test.php
    Document Length:        130 bytes
    
    Concurrency Level:      50
    Time taken for tests:   3.656 seconds
    Complete requests:      100000
    Failed requests:        0
    Write errors:           0
    Keep-Alive requests:    100000
    Total transferred:      37100000 bytes
    HTML transferred:       13000000 bytes
    Requests per second:    27350.70 [#/sec] (mean)
    Time per request:       1.828 [ms] (mean)
    Time per request:       0.037 [ms] (mean, across all concurrent requests)
    Transfer rate:          9909.29 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.1      0       3
    Processing:     0    2   2.7      0      29
    Waiting:        0    2   2.7      0      29
    Total:          0    2   2.7      0      29
    
    Percentage of the requests served within a certain time (ms)
      50%      0
      66%      2
      75%      3
      80%      3
      90%      5
      95%      7
      98%     10
      99%     12
     100%     29 (longest request)
    
    $ cat node-test.js 
    var http = require('http');
    http.createServer(function (req, res) {
              res.writeHead(200, {'Content-Type': 'text/plain'});
                res.end('Hello World\n');
    }).listen(1337, "127.0.0.1");
    console.log('Server running at http://127.0.0.1:1337/');
    
    $ ab -r -n 100000 -k -c 50 http://localhost:1337/
    This is ApacheBench, Version 2.3 <$Revision: 655654 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking localhost (be patient)
    Completed 10000 requests
    Completed 20000 requests
    Completed 30000 requests
    Completed 40000 requests
    Completed 50000 requests
    Completed 60000 requests
    Completed 70000 requests
    Completed 80000 requests
    Completed 90000 requests
    Completed 100000 requests
    Finished 100000 requests
    
    
    Server Software:        
    Server Hostname:        localhost
    Server Port:            1337
    
    Document Path:          /
    Document Length:        12 bytes
    
    Concurrency Level:      50
    Time taken for tests:   14.708 seconds
    Complete requests:      100000
    Failed requests:        0
    Write errors:           0
    Keep-Alive requests:    0
    Total transferred:      7600000 bytes
    HTML transferred:       1200000 bytes
    Requests per second:    6799.08 [#/sec] (mean)
    Time per request:       7.354 [ms] (mean)
    Time per request:       0.147 [ms] (mean, across all concurrent requests)
    Transfer rate:          504.62 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.1      0       3
    Processing:     0    7   3.8      7      28
    Waiting:        0    7   3.8      7      28
    Total:          1    7   3.8      7      28
    
    Percentage of the requests served within a certain time (ms)
      50%      7
      66%      9
      75%     10
      80%     11
      90%     12
      95%     14
      98%     16
      99%     17
     100%     28 (longest request)
    
    $ node --version
    v0.4.8
    

提交回复
热议问题