Skip to main content

01.压力测试

tip

ad测试工具基于docker。安装官方说明文档在这: I`m here!

1. 使用前的镜像中ad工具的别名配置

$ docker run  --rm httpd:2.4.41-alpine  ab -k -c 100 -n 10000 http://jd.wuchuheng.com:9501/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking jd.wuchuheng.com (be patient)
Completed 1000 requests
...

基本上一条命令就搞定了, 格式为 docker run --rm httpd:2.4.41-alpine ab <option> ... 意思是在apache镜像中运行下ad工具后就删除掉容器。由于命令过长可以把开头固定参数进行别名设置:

$ echo "alias ab='docker run  --rm httpd:2.4.41-alpine  ab'" >> ~/.bashrc; # 定义简化的别名并写入用户的bash配置文件
$ source ~/.bashrc; # 重载bash配置文件使别名生效
$ ab -k -c 100 -n 10000 http://jd.wuchuheng.com:9501/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking jd.wuchuheng.com (be patient)
Completed 1000 requests
...

1.1 小结

为什么我要通过docker再去运行apache镜像再在里面运行ab工具这么麻烦?为什么就不能一开始就直接安装apache直在机器运行呢?
linux中不同的发行版本之间的软件安装是不一样的,或编译或源或卸载,总会因为奇奇怪怪的问题而浪费时间。大家想象一下,有没有这样的一个场景,我要什么软件招之即来、我不要什么软件都是挥之即去.docker 可以实现这样的场景,上面我已经配置好了db工具了写在了~/.bashrc中,我到任何的linux主机中,只要安装好docker,然后把我写有大量的工具的配置别名文件.bashrc加载进去,那么就可以直接使用这些工具。没有安装和卸载的概念,所有的工具都是之前已经配置好的放镜像中只要下载下来就可以直接使用也可以直接删除。所以我说...
所以我说这个场景可以实现,首先创建.dotfiles 项目用于存放各种配置各种工具,再写个导入配置的sh 脚本,最后放到代码项目库中,到任何的linux主机是把docker安装下(如果说能把导入脚本强大些就干脆把安装docker 写在当也行)并把设置当前用户可执行docker,把dotfiles 项目拉下来,导入所有的配置就行了。可以参考我个人的dotfiles
结论是: 拥有docker 也许可以拥有世界。

2 100并发10000 请求

$ ab -k -c 100 -n 10000 http://jd.wuchuheng.com:9501/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking jd.wuchuheng.com (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: Hyperf
Server Hostname: jd.wuchuheng.com
Server Port: 9501

Document Path: /
Document Length: 42 bytes

Concurrency Level: 100 #当前并发量
Time taken for tests: 4.980 seconds # 本次100并发症10000次请求完成的时间
Complete requests: 10000 # 本次测试成功的请求量
Failed requests: 0 # 失败的请求量
Keep-Alive requests: 10000
Total transferred: 1900000 bytes
HTML transferred: 420000 bytes
Requests per second: 2007.87 [#/sec] (mean) # 1秒内完成的请求,数字越好
Time per request: 49.804 [ms] (mean) # 完成一次并发(100次)花费时间
Time per request: 0.498 [ms] (mean, across all concurrent requests) # 平均每次请求花费时间
Transfer rate: 372.55 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 4
Processing: 1 49 38.6 78 106
Waiting: 1 49 38.6 78 106
Total: 1 49 38.6 78 106

Percentage of the requests served within a certain time (ms)
50% 78
66% 78
75% 89
80% 89
90% 89
95% 89
98% 89
99% 89
100% 106 (longest request)