我如何轻松测试我的 Web 服务器 ( Apache) 设置可以处理多少个请求,而不会丢失连接或超时。
有没有简单的 bash 脚本,或者我必须使用一些复杂的压力测试工具。
答案1
ab
您可以使用包内的软件进行测试apache2-utils
。例子:
ab -r -n 100 -c 10 -k -H "Accept-Encoding: gzip, deflate" http://mysite.mydomain.com/
-r
:避免因套接字错误而退出。-n
:要执行的请求数。-c
:并发运行的多个请求的数量。-k
:启用 HTTP KeepAlive。意味着它将在每个 Http 会话中执行多个请求。-H
:自定义标头。这在很大程度上取决于您的站点的配置方式。
这是我在一个只有索引页面(php)的简单站点中进行的测试的结果:
# ab -r -n 200 -c 20 -k -H "Accept-Encoding: gzip, deflate" http://intranet.example.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking intranet.example.com (be patient)
Completed 100 requests
Completed 200 requests
Finished 200 requests
Server Software: Apache/2.2.15
Server Hostname: intranet.example.com
Server Port: 80
Document Path: /
Document Length: 10276 bytes
Concurrency Level: 20
Time taken for tests: 38.344 seconds
Complete requests: 200
Failed requests: 0
Write errors: 0
Keep-Alive requests: 0
Total transferred: 2132800 bytes
HTML transferred: 2055200 bytes
Requests per second: 5.22 [#/sec] (mean)
Time per request: 3834.421 [ms] (mean)
Time per request: 191.721 [ms] (mean, across all concurrent requests)
Transfer rate: 54.32 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 2869 3813 383.1 3649 5205
Waiting: 2868 3781 380.4 3613 5161
Total: 2869 3814 383.1 3650 5205
Percentage of the requests served within a certain time (ms)
50% 3650
66% 3763
75% 3971
80% 4318
90% 4451
95% 4530
98% 4634
99% 5093
100% 5205 (longest request)
但是,您必须在测试之间花一些时间,确保您的 httpd 服务没有处于重负载状态,并增加所有参数以对您的服务器造成更大的影响。据我所知,没有工具可以评估此输出并提高动态测量参数的性能。
链接:
- ab 联机帮助页- Apache HTTP 服务器基准测试工具