为什么节点。js比apache 2.4慢得多。

时间:2021-04-07 21:25:19

A few year ago I tested node.js vs apache 2. The results have been impressive. node.js was really fast, especially with high concurrency.

几年前,我测试了node。js和apache 2。结果令人印象深刻。节点。js非常快,尤其是高并发性。

Yesterday I wanted to show that to someone and.... outch apache 2.4 was much faster.

昨天我想表明,有人和....outch apache 2.4要快得多。

The setup:

设置:

Node.js (Express.js, node 6.2.2)

节点。js(表达。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 (serving a php file)

Apache 2.4(服务php文件)

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

I launched apache with port 80 Then I launched the node.js app on port 3000 and tested everything with Apache Benchmark

我用端口80启动了apache,然后我启动了节点。在端口3000上运行js应用程序,并使用Apache Benchmark测试一切

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

Results:

结果:

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

node . js

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

Results:

结果:

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)

The same if I test for n=1000, c=100 ... or higher Apache is always twice as fast.

同样,如果我测试n=1000, c=100…或者更高的Apache总是快两倍。

Did there change anything? Did they speed up apache 2.4 massively? Or did node.js get old and slow?

有任何改变吗?他们是否大量加速了apache 2.4 ?还是节点。变老变慢?

I really remember that node.js was faster as soon as there was a concurrency higher than 5 or 10...

我真的记得那个节点。js的速度比5或10的并发速度快得多……

Am I am wrong? Any comment appreciated.

难道我错了吗?任何评论。

Kind regards Martin

亲切的问候马丁

UPDATE

更新

I found this article in the web http://zgadzaj.com/benchmarking-nodejs-basic-performance-tests-against-apache-php

我在web http://zgadzaj.com/benchmark- nodejs-basic-performance- test- against-apache-php中找到了这篇文章

I cannot reproduce those results. Apache is faster when I try the same settings.

我无法再现这些结果。当我尝试相同的设置时,Apache会更快。

1 个解决方案

#1


3  

Look at the 2 sets of results. Are they the same? There is a difference here: Non-2xx responses: 10000

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

Your test results are not the same so we can't say anything about performance until that is fixed.

你的测试结果是不一样的,所以我们不能说任何关于性能的东西,除非它是固定的。

#1


3  

Look at the 2 sets of results. Are they the same? There is a difference here: Non-2xx responses: 10000

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

Your test results are not the same so we can't say anything about performance until that is fixed.

你的测试结果是不一样的,所以我们不能说任何关于性能的东西,除非它是固定的。