我们先对ApacheBench做个简介,再介绍boom。 ApacheBenchApacheBench简介ApacheBench 是一个用来衡量http服务器性能的单线程命令行工具。原本针对Apache http服务器,但是也适用于其他http服务器。 ab工具与标准 Apache源码一起发布,免费,开源,基于Apache License。 ApacheBench安装ubuntu 14.04 执行“apt-get install apache2-utils“即可。 ApacheBench快速入门发送1000个http get请求到http://192.168.10.232:8000/blog,并发为10: # ab -n1000 -c10 http://192.168.10.232:8000/blogThis is ApacheBench, Version 2.3 <$Revision: 1528965 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 192.168.10.232 (be patient)Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: tracd/1.0.1Server Hostname: 192.168.10.232Server Port: 8000Document Path: /blog Document Length: 330918 bytesConcurrency Level: 10Time taken for tests: 1353.994 seconds Complete requests: 1000Failed requests: 0Total transferred: 331323000 bytesHTML transferred: 330918000 bytesRequests per second: 0.74 [#/sec] (mean)Time per request: 13539.943 [ms] (mean)Time per request: 1353.994 [ms] (mean, across all concurrent requests)Transfer rate: 238.97 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median maxConnect: 1 1 0.8 1 17Processing: 8703 13500 640.5 13586 15076Waiting: 8646 13387 641.6 13480 14957Total: 8704 13501 640.5 13587 15079Percentage of the requests served within a certain time (ms) 50% 13587 66% 13742 75% 13848 80% 13912 90% 14133 95% 14315 98% 14516 99% 14618 100% 15079 (longest request) 注意Time per request: 13539.943 [ms] (mean)是平均每批请求的完成时间,这里时10个请求完成的时间。Time per request: 1353.994 [ms] (mean, across all concurrent requests)是平均每个请求的完成时间。 ApacheBench将只使用一个操作系统线程。很多情况下ApacheBench本身是瓶颈。当在硬件具有多个处理器核心使用ApacheBench,建议一个cpu核执行一个ab线程,但是现在cpu核数很多的情况下,比如48核,手工执行48个命令也是个体力活。 整体来说ab因为不能利用到多核、不能进行参数化、不支持http和https以外的协议等原因,只适合单个组件的粗略测试,比如Apache http。不合适业务级别的测试,如一旦后台有数据库等,ab的测试是几乎没有意义的。 ApacheBench参考
boomboom简介boom是python替代ab的模块,并增加了部分功能。 boom安装ubuntu 14.04 执行“pip install boom“即可,注意可能需要先执行"apt-get install libevent python-dev"。它使用Gevent创建虚拟用户,使用Requests发送请求。 boom快速入门# boom -n1000 -c10 http://192.168.10.232:8000/blogServer Software: tracd/1.0.1 Python/2.7.3Running GET http://192.168.10.232:8000/blog Running 1000 times per 10 workers.[================================================================>.] 99% Done-------- Results --------Successful calls 1000Total time 1355.1412 s Average 13.5156 s Fastest 8.2434 s Slowest 15.3094 s Amplitude 7.0660 s RPS 0BSI Hahahaha-------- Status codes --------Code 200 1000 times.-------- Legend --------RPS: Request Per Second BSI: Boom Speed IndexAverage:每批请求的平均处理时间。 Fastest:每批请求的最快处理时间。 Slowest:每批请求的最慢处理时间。 Amplitude:振幅,即最慢与最忙批次处理时间差。 boom参考$ boom -h usage: boom [-h] [--version] [-m {GET,POST,DELETE,PUT,HEAD,OPTIONS}] [--content-type CONTENT_TYPE] [-D DATA] [-c CONCURRENCY] [-a AUTH] [--header HEADER] [--hook HOOK] [--json-output] [-n REQUESTS | -d DURATION] [url]Simple HTTP Load runner.positional arguments: url URL to hit optional arguments: -h, --help show this help message and exit --version Displays version and exits. -m {GET,POST,DELETE,PUT,HEAD,OPTIONS}, --method {GET,POST,DELETE,PUT,HEAD,OPTIONS} HTTP Method --content-type CONTENT_TYPE Content-Type -D DATA, --data DATA Data. Prefixed by "py:" to point a python callable. -c CONCURRENCY, --concurrency CONCURRENCY Concurrency -a AUTH, --auth AUTH Basic authentication user:password --header HEADER Custom header. name:value --hook HOOK Python callable that'll be used on every requests call --json-output Prints the results in JSON instead of the default format -n REQUESTS, --requests REQUESTS Number of requests -d DURATION, --duration DURATION Duration in seconds 结论ab和boom在功能上远不及multi-mechanize和Grinder等主力python性能测试工具,甚至还比不上庞大且扩能能力差的loadrunner。只建议在对单个中间件的基准测试时使用。 |