繁体   English   中英

使用 apache 基准测试 PM2 nodeJS 集群模式测试

[英]PM2 nodeJS cluster mode testing with apache benchmark

我已经设置了一个只有一个路由“/”的 nodeJS 应用程序,并且我使用 Nginx 作为反向代理。 所以应用流程如下:

  • 用户将请求发送到 Nginx 服务器。
  • 并且根据位置'/' Nginx 服务器将请求传递给节点服务器。

在 nodeJS 中,'/' 路由发送一个 HTML 文件作为对客户端的响应。 对于负载测试,我使用了 apache 基准测试。

用于测试的 Apache 基准命令:

ab -k -c 250 -n 10000 http://localhost/

请在以下两种情况下检查 apache 基准测试响应:

情况 1:未开启聚类模式时。 (没有pm2,没有集群的简单nodeJS服务器,例如:node index.js)

rails@rails-laptop:~$ ab -k -c 250 -n 10000 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
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 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        nginx/1.10.3
Server Hostname:        localhost
Server Port:            80

Document Path:          /
Document Length:        134707 bytes

Concurrency Level:      250
Time taken for tests:   9.531 seconds
Complete requests:      10000
Failed requests:        0
Keep-Alive requests:    10000
Total transferred:      1350590000 bytes
HTML transferred:       1347070000 bytes
Requests per second:    1049.26 [#/sec] (mean)
Time per request:       238.264 [ms] (mean)
Time per request:       0.953 [ms] (mean, across all concurrent requests)
Transfer rate:          138390.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.8      0       6
Processing:    38  237  77.6    213     626
Waiting:       31  230  73.8    209     569
Total:         44  237  77.5    213     626

Percentage of the requests served within a certain time (ms)
  50%    213
  66%    229
  75%    247
  80%    280
  90%    373
  95%    395
  98%    438
  99%    538
 100%    626 (longest request)

案例2:当PM2集群模式为ON时。(pm2 start index.js -i 4 (4 cluster))

rails@rails-laptop:~$ ab -k -c 250 -n 10000 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
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 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        nginx/1.10.3
Server Hostname:        localhost
Server Port:            80

Document Path:          /
Document Length:        134707 bytes

Concurrency Level:      1
Time taken for tests:   14.109 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1350540000 bytes
HTML transferred:       1347070000 bytes
Requests per second:    708.79 [#/sec] (mean)
Time per request:       1.411 [ms] (mean)
Time per request:       1.411 [ms] (mean, across all concurrent requests)
Transfer rate:          93481.05 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       9
Processing:     1    1   1.2      1      35
Waiting:        0    1   0.9      1      21
Total:          1    1   1.2      1      35

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      2
  95%      3
  98%      5
  99%      6
 100%     35 (longest request)

现在,如果您比较这两种情况下的每秒请求数,您会看到当没有使用集群模式时每秒请求数 (1049.26 [#/sec] (mean)) 高于 pm2 集群模式 (708.79 [#/秒](平均)) 我不明白为什么会这样? 据我所知,集群模式是为了实现更高级别的并发,但为什么结果会出现冲突?

我尝试使用不同的参数进行聚类:

  • 没有过程

  • 计算

    for(let i = 1; i <= 50000000; i++){ r += i; }
  • 发送文件

  • 并发请求数

这是git 仓库

这是我的结论:

  • 对于服务文件,集群没有意义。 我认为网络是这里的瓶颈,聚类无济于事。
  • 对于计算,集群确实有意义,因为它使事件循环保持忙碌,如果您进行集群,则有多个事件循环要保持忙碌。 在进行计算测试时,我通过htop检查了服务器核心进程,我认为与 CPU 100% 忙碌的集群数量相同。 性能乘以集群数,比如我做了6个节点的集群,性能变成了6倍。
  • 集群超过机器上的 CPU 内核是没有意义的。 我建议为操作系统保留一个核心。

我创建了一个存储库,并在自述文件中写下了详细的结果。

暂无
暂无

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

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