yaogengzhu / Learning-notes

基础回顾、笔记
1 stars 0 forks source link

如何调试nodeJs 性能, ab 测试工具 #53

Open yaogengzhu opened 4 weeks ago

yaogengzhu commented 4 weeks ago

ab(Apache Bench)是一个常用的命令行工具,用于对 HTTP 服务器进行性能测试。ab -k -c 20 -n 250 是一个具体的命令,下面是对每个参数和整体命令含义的解释:

命令参数解释

整体命令含义

ab -k -c 20 -n 250 的含义是:

输出结果解释

执行上述命令后,ab 会输出一系列性能指标,以下是一些关键指标及其含义:

总体统计

成功与失败

传输速率

错误统计

示例输出

Server Software:        Apache/2.4.41
Server Hostname:        example.com
Server Port:            80

Document Path:          /
Document Length:        1270 bytes

Concurrency Level:      20
Time taken for tests:   10.000 seconds
Complete requests:      250
Failed requests:        0
Non-2xx responses:       0
Total transferred:      322500 bytes
HTML transferred:       317500 bytes
Requests per second:    25.00 [#/sec] (mean)
Time per request:       800.000 [ms] (mean)
Time per request:       40.000 [ms] (mean, across all concurrent requests)
Transfer rate:          31.25 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      5
Processing:    50  750 100.0    740    900
Waiting:       50  750 100.0    740    900
Total:         50  751 100.0    741    905

解读示例输出

通过这些指标,你可以评估服务器的性能,并找出潜在的瓶颈。例如,如果 Time per request 过高,可能需要优化服务器代码或增加服务器资源。

yaogengzhu commented 4 weeks ago

参考: https://nodejs.org/zh-cn/learn/getting-started/profiling