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请求。

相关推荐
网络豆1 小时前
Apache Hive 鸿蒙 PC 适配全记录:以 Qt 客户端打通 HiveQL、监控与元数据访问
hive·apache·harmonyos
网络豆1 小时前
Apache HBase 鸿蒙 PC 适配全记录:用 Qt 原生客户端打通 REST 管理与数据读写
apache·hbase·harmonyos
测试199821 小时前
Jmeter接口自动化测试:Jmeter变量的使用
自动化测试·软件测试·测试工具·jmeter·职场和发展·测试用例·接口测试
无巧不成书02181 天前
Apache Tomcat 9 下载全指南(Windows,Linux,macOS):版本选型、国内镜像、SHA-512 与 PGP 完整性校验
windows·tomcat·apache
Dream-Y.ocean1 天前
鸿蒙平台 Apache Tomcat 管理控制台适配实战:基于 Electron 壳方案的真实 HTTP 服务器实现
tomcat·apache·harmonyos
betazhou1 天前
Apache seatunel常用配置参数解析说明
apache·seatunnel
Tinyfacture2 天前
postman抓取登录鉴权码token及设置全局变量
测试工具·postman
川石课堂软件测试2 天前
涨薪技术|Prometheus之HTTP API中使用PromQL
网络协议·测试工具·jmeter·http·单元测试·postman·prometheus
凤山老林2 天前
Spring Boot 集成 Apache Kafka Streams 构建流处理应用:状态存储、窗口聚合与
spring boot·kafka·apache