简介
Multi-Mechanize 是一个开源的性能和负载测试框架,它并发运行多个 Python 脚本对网站或者服务生成负载(组合事务)。测试输出报告保存为HTML或JMeter的兼容的XML。Multi-Mechanize最常用于web性能和可扩展性(scalability)测试,也适用于任何python可以访问的API。尤其适合后台性能测试。稍微懂点编程的话,这个工具会远强过商业的性能测试工具。
主要特性
- 支持各种 HTTP methods
- 高级超链接和HTML表单支持
- 支持 SSL
- 自动处理 Cookies
- 可设置HTTP头
- 自动处理重定向
- 支持代理
- 支持 HTTP 认证
安装 Install / Setup 参考
Multi-Mechanize can be installed from PyPI using pip:
pip install -U multi-mechanize
... or download the source distribution from PyPI, unarchive, and run:
python setup.py install
需要安装 Matplotlib 便于生成图片
pip install Matplotlib
创建项目
multimech-newproject multimech_demo
自动创建一个multimech_demo目录,子目录test_scripts用来放测试脚本,config.cfg是测试配置,主要要配的是测试时间、测试脚本和并发threads量。
执行项目
multimech-run multimech_demo
项目目录说明
每个测试项目包含以下内容:
- config.cfg的配置文件。用于设定测试选项。
- test_scripts/虚拟用户脚本的目录。在这里添加您的测试脚本。
- results/:结果存储目录。对于每个测试都声称一个时间戳目录,里面包含结果的报告。
配置参数的含义如下:
- run_time: duration of test (seconds) 测试的执行时间
- rampup: duration of user rampup (seconds) 多少秒内发完请求
- results_ts_interval: time series interval for results analysis (seconds) 结果分析时间
- progress_bar: turn on/off console progress bar during test run 是否显示进度条
- console_logging: turn on/off logging to stdout 是否输出到stdout
- xml_report: turn on/off xml/jtl report 是否生成xml报告。
- results_database: database connection string (optional) 保存结果的数据库连接字符串(可选)
- post_run_script: hook to call a script at test completion (optional) 调用的善后脚本(可选)
脚本
并发请求聊天室
参考代码: test_scripts/chat_create.py