python标准模块介绍-性能测试工具boom

boom简介

boom是python替代ab的模块,并增加了部分功能。

boom安装

ubuntu 执行“pip install boom“即可,注意可能需要先执行"apt-get install libevent python-dev"。它使用Gevent创建虚拟用户,使用Requests发送请求。

boom快速入门

# boom -n1000 -c10 http://localhost
/usr/local/anaconda3/lib/python3.6/site-packages/boom/boom.py:28: MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016
  monkey.patch_all()
Server Software: nginx/1.10.3 (Ubuntu)
Running GET http://127.0.0.1:80
    Host: localhost
Running 1000 queries - concurrency 10
[================================================================>.] 99% Done

-------- Results --------
Successful calls        1000
Total time              4.7209 s  
Average                 0.0405 s  
Fastest                 0.0128 s  
Slowest                 0.0732 s  
Amplitude               0.0604 s  
Standard deviation      0.009018
RPS                     211
BSI                     Pretty good

-------- Status codes --------
Code 200                1000 times.

-------- Legend --------
RPS: Request Per Second
BSI: Boom Speed Index

Average:每批请求的平均处理时间。 Fastest:每批请求的最快处理时间。 Slowest:每批请求的最慢处理时间。 Amplitude:振幅,即最慢与最忙批次处理时间差。

boom参考

# boom -h
/usr/local/anaconda3/lib/python3.6/site-packages/boom/boom.py:28: MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016
  monkey.patch_all()
usage: boom [-h] [--version] [-m {GET,POST,DELETE,PUT,HEAD,OPTIONS}]
            [--content-type CONTENT_TYPE] [-D DATA] [-c CONCURRENCY] [-a AUTH]
            [--header HEADER] [--pre-hook PRE_HOOK] [--post-hook POST_HOOK]
            [--json-output] [-q] [-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
  --pre-hook PRE_HOOK   Python module path (eg: mymodule.pre_hook) to a
                        callable which will be executed before doing a request
                        for example: pre_hook(method, url, options). It must
                        return a tupple of parameters given in function
                        definition
  --post-hook POST_HOOK
                        Python module path (eg: mymodule.post_hook) to a
                        callable which will be executed after a request is
                        done for example: eg. post_hook(response). It must
                        return a given response parameter or raise an
                        `boom.boom.RequestException` for failed request.
  --json-output         Prints the results in JSON instead of the default
                        format
  -q, --quiet           Don't display progress bar
  -n REQUESTS, --requests REQUESTS
                        Number of requests
  -d DURATION, --duration DURATION
                        Duration in seconds

结论

ab和boom在功能上远不及multi-mechanize和nGrinder、Locust等主力python性能测试工具,甚至还比不上庞大且扩能能力差的loadrunner。只建议在对单个中间件的基准测试时使用。

参考资料

links