繁体   English   中英

为什么node.js比Apache 2.4慢得多

[英]Why is node.js so much slower than apache 2.4

几年前,我测试了node.js和apache2。结果令人印象深刻。 node.js确实非常快,特别是具有高并发性。

昨天我想向某人展示,.. outch apache 2.4快得多。

设置:

Node.js(Express.js,节点6.2.2)

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Apache 2.4(提供php文件)

<?php
  $foo = "Hello";
  $bar = "World";
  echo "$foo $bar";
?>

我使用端口80启动了apache,然后在端口3000中启动了node.js应用程序,并使用Apache Benchmark测试了所有内容

ab -r -n 10000 -c 10 http://127.0.0.1/

结果:

Server Software:        Apache/2.4.18
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   4.439 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1980000 bytes
HTML transferred:       110000 bytes
Requests per second:    2252.97 [#/sec] (mean)
Time per request:       4.439 [ms] (mean)
Time per request:       0.444 [ms] (mean, across all concurrent requests)
Transfer rate:          435.63 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.3      0      12
Processing:     1    3   1.8      3      88
Waiting:        0    3   1.5      3      38
Total:          1    4   1.8      4      91

Percentage of the requests served within a certain time (ms)
  50%      4
  66%      4
  75%      5
  80%      5
  90%      6
  95%      7
  98%      9
  99%     10
 100%     91 (longest request)

Node.js的

ab -r -n 10000 -c 10 http://127.0.0.1/

结果:

Server Software:
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /
Document Length:        19 bytes

Concurrency Level:      10
Time taken for tests:   8.513 seconds
Complete requests:      10000
Failed requests:        0
Non-2xx responses:      10000
Total transferred:      4020000 bytes
HTML transferred:       190000 bytes
Requests per second:    1174.64 [#/sec] (mean)
Time per request:       8.513 [ms] (mean)
Time per request:       0.851 [ms] (mean, across all concurrent requests)
Transfer rate:          461.14 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       7
Processing:     1    8   4.4      8      69
Waiting:        0    8   4.3      7      69
Total:          2    8   4.4      8      69

Percentage of the requests served within a certain time (ms)
  50%      8
  66%      9
  75%     10
  80%     10
  90%     12
  95%     15
  98%     20
  99%     23
 100%     69 (longest request)

如果我测试n = 1000,c = 100 ...或更高,则相同,Apache的运行速度总是两倍。

有什么变化吗? 他们是否大大加快了Apache 2.4的速度? 还是node.js变老变慢了?

我真的记得当并发高于5或10时,node.js会更快。

我说错了吗 任何评论表示赞赏。

亲切的问候马丁

UPDATE

我在网站http://zgadzaj.com/benchmarking-nodejs-basic-performance-tests-against-apache-php中找到了这篇文章

我无法复制这些结果。 当我尝试相同的设置时,Apache速度更快。

查看2组结果。 他们是一样的吗? 这里有一个区别:非2xx响应:10000

您的测试结果是不同的,因此,在解决该问题之前,我们无法谈论性能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM