Apache的ab压力测试工具与性能监控

【图书介绍】《软件性能测试、分析与调优实践之路(第2版)》_软件性能测试分析与调优实践之路-CSDN博客
《软件性能测试、分析与调优实践之路(第2版)》(张永清)【摘要 书评 试读】- 京东图书 (jd.com)

Apache的ab压力测试工具

Apache中自带了性能压测工具ab,一些比较简单的压力测试请求可以直接使用这个性能压测工具ab来完成。ab使用起来非常简单方便,直接可以通过命令行执行ab命令,或者在命令后面加上对应的参数即可开启性能压测。

ab支持的常用参数如下:

  1. -n requests:表示总计发送多少请求。
  2. -c concurrency:代表客户端请求的并发连接的数量。
  3. -k:开启Http KeepAlive。
  4. -s timeout:设置响应的超时时间,默认为30秒。
  5. -b windowsize:设置TCP请求发送和接收的缓冲区大小,单位为字节。
  6. -f protocol:指定SSL/TLS协议(支持SSL3、TLS1、TLS1.1、TLS1.2或者all)。
  7. -g filename:输出收集到的压测数据到gnuplot 格式的文件中,gnuplot是一个命令行的交互式绘图工具。
  8. -e filename:输出收集到的压测数据到csv 格式的文件中。
  9. -r:表示在socket接收到错误时,ab压测不退出。
  10. -X proxy:port:设置压测请求地址的代理服务器地址。

示例:ab -n 10000 -c 60 -k http://127.0.0.1:80/ 表示总共发送10 000次压测请求,并发连接数为60,并且在压测时客户端开启KeepAlive。

复制代码
[root@localhost conf]# ab -n 10000 -c 60 -k  http://127.0.0.1:80/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (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:        Apache/2.4.6
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /
Document Length:        4897 bytes

Concurrency Level:      60
Time taken for tests:   4.014 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Non-2xx responses:      10000
Keep-Alive requests:    9916
Total transferred:      52046232 bytes
HTML transferred:       48970000 bytes
Requests per second:    2491.21 [#/sec] (mean)
Time per request:       24.085 [ms] (mean)
Time per request:       0.401 [ms] (mean, across all concurrent requests)
Transfer rate:          12661.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.5      0       8
Processing:     0   11  65.9      8    2474
Waiting:        0   11  65.9      7    2474
Total:          0   11  66.0      8    2474

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

Apache的性能监控

Apache自身自带了状态监控页面,但是默认是关闭的,可以通过在httpd.conf中增加如下配置来打开监控页面。

复制代码
<location /server-status>

    SetHandler server-status

    Order Deny,Allow

    Allow from all

</location>

增加上述配置后,然后就可以通过访问http://ip:port/server‐status来查看监控页面了,如图3-2-6和图3-2-7所示。

图3-2-6

图3-2-7

从上图中可以看到如下数据:

(1)Total accesses:对Apache的访问量。

(2)Total Traffic:Apache的访问流量,单位为KB。

(3)CPU Usage:CPU的使用情况。

(4)每秒收到的请求的统计信息:0.0513 requests/sec - 105 B/second - 2048 B/request,表示平均每秒收到0.0513个请求,平均每秒收到的请求流量为105字节,每个请求的平均大小为2048字节。

(5)请求的处理情况:1 requests currently being processed, 8 idle workers,表示目前1个请求正在被处理(状态为w,表示处理发送回复状态),目前有8个线程处于空闲状态。

(6)目前运行的Apache进程的资源使用情况以及客户端的连接情况,如图3-2-8所示。

图3-2-8

从图中可以看到,当前有4个进程正在工作中,并且PID为1925的进程当前正在处理一个HTTP的GET请求。

相关推荐
freejackman11 小时前
【工程化】从“单兵作战”到“多引擎架构”:基于门面模式的重构实战
大数据·数据库·hive·sql·测试工具·设计模式·架构
坐吃山猪14 小时前
Python22-PostMan调试MCP
测试工具·postman·mcp
测试界的小码农2 天前
【 AI Agent 软件测试实战(05):任务规划与状态管理,让 Agent 学会拆解复杂测试任务】
人工智能·测试工具
和粒科技3 天前
热重分析仪TG 309 Libra Classic
测试工具
源图客8 天前
Apache Flink 2.3.0(最新版本)
大数据·flink·apache
螺丝钉tina9 天前
[Playwright] [02]常用命令与调试:Debug UI、Mode和 Trace Viewer
开发语言·javascript·测试工具·ui·自动化
梧桐16810 天前
14天、31个缺陷、28个测试脚本—用 Claude Code 完成第三方软件测试
人工智能·测试工具
代立冬10 天前
927 个 PR:Apache SeaTunnel 3.0.0 正式发布!AI 时代,数据集成正在迎来新的可能
人工智能·apache
mewowaBc11 天前
postman使用细则
测试工具·postman·偏差
光影62711 天前
Unittest单元测试基础速记
测试工具·单元测试·json·测试覆盖率