$ docker run --name nginx-hostnet --privileged --network=host -itd feisky/nginx:80
然后到终端二中,执行 curl 命令,确认 Nginx 正常启动:
1 2 3 4 5 6
$ curl http://192.168.0.30/ ... <p><em>Thank you for using nginx.</em></p> </body> </html>
继续在终端二中,执行 ab 命令,对 Nginx 进行压力测试。不过在测试前要注意,Linux 默认允许打开的文件描述数比较小,比如在我的机器中,这个值只有 1024:
1 2 3 4
# open files $ ulimit -n 1024
所以,执行 ab 前,先要把这个选项调大,比如调成 65536:
1 2 3
# 临时增大当前会话的最大文件描述符数 $ ulimit -n 65536
接下来,再去执行 ab 命令,进行压力测试:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# -c表示并发请求数为5000,-n表示总的请求数为10万 # -r表示套接字接收错误时仍然继续执行,-s表示设置每个请求的超时时间为2s $ ab -c 5000 -n 100000 -r -s 2 http://192.168.0.30/ ... Requests per second: 6576.21 [#/sec] (mean) Time per request: 760.317 [ms] (mean) Time per request: 0.152 [ms] (mean, across all concurrent requests) Transfer rate: 5390.19 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 0 177 714.3 9 7338 Processing: 0 27 39.8 19 961 Waiting: 0 23 39.5 16 951 Total: 1 204 716.3 28 7349 ...
$ curl http://192.168.0.30:8080/ ... <p><em>Thank you for using nginx.</em></p> </body> </html>
然后,再次执行上述的 ab 命令,不过这次注意,要把请求的端口号换成 8080:
1 2 3 4 5 6 7
# -c表示并发请求数为5000,-n表示总的请求数为10万 # -r表示套接字接收错误时仍然继续执行,-s表示设置每个请求的超时时间为2s $ ab -c 5000 -n 100000 -r -s 2 http://192.168.0.30:8080/ ... apr_pollset_poll: The timeout specified has expired (70007) Total of 5602 requests completed
果然,刚才正常运行的 ab ,现在失败了,还报了连接超时的错误。运行 ab 时的-s 参数,设置了每个请求的超时时间为 2s,而从输出可以看到,这次只完成了 5602 个请求。
既然是为了得到 ab 的测试结果,把超时时间延长,延长到 30s。延迟增大意味着要等更长时间,为了快点得到结果,我们可以同时把总测试次数,也减少到 10000:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$ab-c5000-n10000-r-s30http://192.168.0.30:8080/ ... Requests per second:76.47 [#/sec] (mean) Time per request:65380.868 [ms] (mean) Time per request:13.076 [ms] (mean, acrossallconcurrentrequests) Transfer rate:44.79 [Kbytes/sec] received
############################################################ # Dropwatch.stp # Author: Neil Horman <nhorman@redhat.com> # An example script to mimic the behavior of the dropwatch utility # http://fedorahosted.org/dropwatch ############################################################
# Array to hold the list of drop points we find global locations
# Note when we turn the monitor on and off probe begin { printf("Monitoring for dropped packets\n") } probe end { printf("Stopping dropped packet monitor\n") }
# increment a drop counter for every location we drop at probe kernel.trace("kfree_skb") { locations[$location] <<< 1 }
# Every 5 seconds report our drop locations probe timer.sec(5) { printf("\n") foreach (l in locations-) { printf("%d packets dropped at %s\n", @count(locations[l]), symname(l)) } delete locations }
$ ab -c 5000 -n 100000 -r -s 2 http://192.168.0.30:8080/ ... Requests per second: 6315.99 [#/sec] (mean) Time per request: 791.641 [ms] (mean) Time per request: 0.158 [ms] (mean, across all concurrent requests) Transfer rate: 4985.15 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 0 355 793.7 29 7352 Processing: 8 311 855.9 51 14481 Waiting: 0 292 851.5 36 14481 Total: 15 666 1216.3 148 14645