1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 压力测试工具Apache Bench:2:基于Alpine的Apache Bench镜像

压力测试工具Apache Bench:2:基于Alpine的Apache Bench镜像

时间:2021-05-29 13:33:04

相关推荐

压力测试工具Apache Bench:2:基于Alpine的Apache Bench镜像

Apache Bench是Apache服务应用服务器自带的性能测试软件。这篇文章介绍一下如何使用Alpine基础镜像将Apache Bench的压测能力进行容器化,并结合具体的示例来演示此镜像从构建到使用的整体过程。

以Alpine为基础构建Apache Bench镜像

Alpine镜像的特点就是小,而Apache Bench本身就是apache2-utils包中的一个工具,所以只需要在Alpine中执行apk add apache2-utils即可完成Apache Bench的镜像化。

Dockerfile

Dockerfile信息如下所示

liumiaocn:ab liumiao$ lsDockerfileliumiaocn:ab liumiao$ cat Dockerfile FROM alpine:3.10.2RUN apk update\&& apk add apache2-utils \&& rm -rf /var/cache/apk/*liumiaocn:ab liumiao$

构建Apache Bench镜像

使用docker build构建Apache Bench镜像,执行日志如下所示:

liumiaocn:ab liumiao$ docker build -t apachebench:2.3 .Sending build context to Docker daemon 2.048kBStep 1/2 : FROM alpine:3.10.23.10.2: Pulling from library/alpine9d48c3bd43c5: Pull complete Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fbStatus: Downloaded newer image for alpine:3.10.2---> 961769676411Step 2/2 : RUN apk update&& apk add apache2-utils&& rm -rf /var/cache/apk/*---> Running in 3b0991f27efafetch http://dl-/alpine/v3.10/main/x86_64/APKINDEX.tar.gzfetch http://dl-/alpine/v3.10/community/x86_64/APKINDEX.tar.gzv3.10.2-80-g68e4e4a13a [http://dl-/alpine/v3.10/main]v3.10.2-83-g64319a6606 [http://dl-/alpine/v3.10/community]OK: 10336 distinct packages available(1/5) Installing libuuid (2.33.2-r0)(2/5) Installing apr (1.6.5-r0)(3/5) Installing expat (2.2.8-r0)(4/5) Installing apr-util (1.6.1-r6)(5/5) Installing apache2-utils (2.4.41-r0)Executing busybox-1.30.1-r2.triggerOK: 6 MiB in 19 packagesRemoving intermediate container 3b0991f27efa---> 2dc7eca87521Successfully built 2dc7eca87521Successfully tagged apachebench:2.3liumiaocn:ab liumiao$

构建结果确认

构建的Alpine基础镜像的大小为5.58M

liumiaocn:ab liumiao$ docker images |grep alpine |grep 3.10.2alpine 3.10.2961769676411 6 weeks ago5.58MBliumiaocn:ab liumiao$

而生成的Apache Bench的镜像大小为6.41M

liumiaocn:ab liumiao$ docker images |grep apachebenchapachebench 2.3 2dc7eca87521 2 minutes ago 6.41MBliumiaocn:ab liumiao$

使用示例

环境准备:测试应用

在本地机器的8088端口使用Docker启动一个Nginx应用(使用其他方式也可),示例如下所示:

liumiaocn:~ liumiao$ docker images |grep nginx |grep latestnginx lateste445ab08b2be 2 months ago 126MBliumiaocn:~ liumiao$ docker run -p 8088:80 -d --name=nginx-test nginx:latesta80fb1a4fc20627891a6bd7394fd79ae9aefb7dc8cf72c12967bc2673a815308liumiaocn:~ liumiao$

使用curl命令或者直接使用浏览器确认nginx已正常运行

liumiaocn:~ liumiao$ curl http://localhost:8088/<!DOCTYPE html><html><head><title>Welcome to nginx!</title><style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.</p><p>For online documentation and support please refer to<a href="/"></a>.<br/>Commercial support is available at<a href="/"></a>.</p><p><em>Thank you for using nginx.</em></p></body></html>liumiaocn:~ liumiao$

ab版本确认

liumiaocn:ab liumiao$ docker run -it --rm apachebench:2.3 ab -VThis is ApacheBench, Version 2.3 <$Revision: 1843412 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, /Licensed to The Apache Software Foundation, /liumiaocn:ab liumiao$

执行压测

压测内容:对http://192.168.31.242:8088/并发启动100个进程,平均10次,共计执行1000次

执行命令如下所示:

执行命令:ab -n 1000 -c 100 http://192.168.31.242:8088/

执行参数说明:

-n: 测试执行总次数-c: 并行度,类似JMeter中的线程组和LR中的Virtual User

执行日志如下所示:

liumiaocn:ab liumiao$ docker run -it --rm apachebench:2.3 ab -n 1000 -c 100 http://192.168.31.242:8088/This is ApacheBench, Version 2.3 <$Revision: 1843412 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, /Licensed to The Apache Software Foundation, /Benchmarking 192.168.31.242 (be patient)Completed 100 requestsCompleted 200 requestsCompleted 300 requestsCompleted 400 requestsCompleted 500 requestsCompleted 600 requestsCompleted 700 requestsCompleted 800 requestsCompleted 900 requestsCompleted 1000 requestsFinished 1000 requestsServer Software: nginx/1.17.2Server Hostname: 192.168.31.242Server Port: 8088Document Path:/Document Length: 612 bytesConcurrency Level:100Time taken for tests: 0.791 secondsComplete requests:1000Failed requests: 0Total transferred:845000 bytesHTML transferred: 612000 bytesRequests per second: 1264.94 [#/sec] (mean)Time per request: 79.055 [ms] (mean)Time per request: 0.791 [ms] (mean, across all concurrent requests)Transfer rate:1043.82 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median maxConnect: 1 12 2.71125Processing: 10 38 6.43855Waiting: 2 28 5.72852Total: 11 49 7.54970Percentage of the requests served within a certain time (ms)50%4966%5275%5580%5690%5995%6198%6599%66100%70 (longest request)liumiaocn:ab liumiao$

结果的说明与介绍可参看:/liumiaocn/article/details/101924143

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。