Locust性能测试工具的安装及实际应用
一、安装Locust
安装Locust之前先安装的库:
gevent库:第三方库,gevent为python提供了比较完善的协程支持。使用gevent,可以获得极高的并发性能。
pip install gevent==1.1.2
flask库:Flask是一个使用 Python 编写的轻量级 Web 应用框架。
pip install flask==0.10.1
requests库:用python写过接口测试的朋友应该都不陌生,Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库。它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTTP 测试需求。
pip install requests==2.10.0
msgpack-python库:比JSON快10倍的序列化包。
pip install msgpack-python==0.4.2
six库:six 提供了一些简单的工具用来封装 Python 2 和 Python 3 之间的差异性。
pip install six==1.10.0
pyzmq库:Pyzmq是zeromq的Python绑定。
pip install pyzmq==15.2.0
安装库的过程中可能会遇到一些报错信息:
ReadTimeoutError: HTTPSConnectionPool(host=’pypi.python.org’, port=443): Read timed out.
解决方案:
更新pip版本到pip官网下载:https://pypi.python.org/simple/pip/
比如下载pip-9.0.1-py2.py3-none-any.whl
pip install pip-9.0.1-py2.py3-none-any.whl
如果还报错再执行:
pip –default-timeout=100 install -U pip
其他第三方库都安装完成后,接下来再安装locust:
pip install locustio
安装locustio库时可能会报错:
error:command ‘gcc’ failed with exit status 1
解决方案:yum install gcc python-devel
安装完成后,执行:locust–help
看到如下locust相关命令介绍,说明安装成功。
Usage: locust [options] [LocustClass [LocustClass2 … ]]
Options:
-h, –help show this help message and exit
-H HOST, –host=HOST Host to load test in the following format:
http://10.21.32.33
–web-host=WEB_HOST Host to bind the web interface to. Defaults to ” (all
interfaces)
-P PORT, –port=PORT, –web-port=PORT
Port on which to run web host
-f LOCUSTFILE, –locustfile=LOCUSTFILE
Python module file to import, e.g. ‘../other.py’.
Default: locustfile
–master Set locust to run in distributed mode with this
process as master
–slave Set locust to run in distributed mode with this
process as slave
–master-host=MASTER_HOST
Host or IP address of locust master for distributed
load testing. Only used when running with –slave.
Defaults to 127.0.0.1.
–master-port=MASTER_PORT
The port to connect to that is used by the locust
master for distributed load testing. Only used when
running with –slave. Defaults to 5557. Note that
slaves will also connect to the master node on this
port + 1.
–master-bind-host=MASTER_BIND_HOST
Interfaces (hostname, ip) that locust master should
bind to. Only used when running with –master.
Defaults to * (all available interfaces).
–master-bind-port=MASTER_BIND_PORT
Port that locust master should bind to. Only used when
running with –master. Defaults to 5557. Note that
Locust will also use this port + 1, so by default the
master node will bind to 5557 and 5558.
–no-web Disable the web interface, and instead start running
the test immediately. Requires -c and -r to be
specified.
-c NUM_CLIENTS, –clients=NUM_CLIENTS
Number of concurrent clients. Only used together with
–no-web
-r HATCH_RATE, –hatch-rate=HATCH_RATE
The rate per second in which clients are spawned. Only
used together with –no-web
-n NUM_REQUESTS, –num-request=NUM_REQUESTS
Number of requests to perform. Only used together with
–no-web
-L LOGLEVEL, –loglevel=LOGLEVEL
Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL.
Default is INFO.
–logfile=LOGFILE Path to log file. If not set, log will go to
stdout/stderr
–print-stats Print stats in the console
–only-summary Only print the summary stats
-l, –list Show list of possible locust classes and exit
–show-task-ratio print table of the locust classes’ task execution
ratio
–show-task-ratio-json
print json data of the locust classes’ task execution
ratio
-V, –version show program’s version number and exit
二、使用Locust测试淘宝首页
#locust_taobao.py #!/usr/bin/env python
#-*-coding:utf-8-*-
#author:@TT from locust import HttpLocust, TaskSet, task
#定义用户行为
class UserBehavior(TaskSet): @task
def taobao_page(self): #定义一个方法访问淘宝首页
self.client.get("/") class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 3000 #用户等待时间下限
max_wait = 5000 #用户等待时间上限
执行:
locust -f locust_taobao.py --host=https://www.taobao.com
提示:Starting web monitor at *.8089
Starting Locust 0.7.5
说明已经启动成功,浏览器输入:http://120.76.139.13:8089即可看到设置页面,并监控

Number of users to simulate:设置需要模拟的用户数量,这次只是为了演示,设置为10;
Hatch rate:每秒需要启动的用户数量,这次只是为了演示,设置为2;
点击『start swarming』,开始了性能测试:

Type:请求的类型;
Name:请求的url或者自定义的统计分组名字;
requests:当前请求的数量;
fails:当前请求失败的数量;
Median:中间值,一半的服务器响应时间高于该值,而另一半的服务器响应时间低于该值(毫秒);
Average:所有请求的平均响应时间(毫秒);
Min:请求最小响应时间(毫秒);
Max:请求最大响应时间(毫秒);
Content Size:单个请求的大小(字节);
reqs/sec:每秒请求的个数;
今天就先整理到这里,如果按照以上内容操作,对Locust的安装和性能测试的执行有了大概的了解。后续会不断更新……
了解更多请关注微信公众号:测试架构师

Locust性能测试工具的安装及实际应用的更多相关文章
- Locust性能测试工具核心技术@task和@events
Tasks和Events是Locust性能测试工具的核心技术,有了它们,Locust才能称得上是一个性能工具. Tasks 从上篇文章知道,locustfile里面必须要有一个类,继承User类,当性 ...
- Locust 性能测试工具安装使用说明
1. 介绍 它是一个开源性能测试工具.使用 Python 代码来定义用户行为.用它可以模拟百万计的并发用户访问你的系统. 性能工具对比 LoadRunner 是非常有名的商业性能测试工具,功能 ...
- 性能测试工具 wrk 安装与使用
介绍 今天给大家介绍一款开源的性能测试工具 wrk,简单易用,没有Load Runner那么复杂,他和 apache benchmark(ab)同属于性能测试工具,但是比 ab 功能更加强大,并且可以 ...
- 云存储性能测试工具--COSBench安装
COSBench安装 Cosbench是Intel的开源云存储性能测试软件,COSBench目前已经广泛使用与云存储测试,并作为云存储的基准测试工具使用 1 环境 1.1 操作系统 COSBench可 ...
- 002_性能测试工具wrk安装与使用
介绍 今天给大家介绍一款开源的性能测试工具 wrk,简单易用,没有Load Runner那么复杂,他和 apache benchmark(ab)同属于性能测试工具,但是比 ab 功能更加强大,并且可以 ...
- HTTP性能测试工具wrk安装及使用
wrk 是一个很简单的 http 性能测试工具,没有Load Runner那么复杂,他和 apache benchmark(ab)同属于HTTP性能测试工具,但是比 ab 功能更加强大,并且可以支持l ...
- Mysql多线程性能测试工具sysbench 安装、使用和测试
From:http://www.cnblogs.com/zhoujinyi/archive/2013/04/19/3029134.html 摘要: sysbench是一个开源的.模块化的.跨 ...
- RGW/SWIFT对象存储性能测试工具--COSBench安装
Cosbench是Intel的开源云存储性能测试软件,COSBench目前已经广泛使用与云存储测试,并作为云存储的基准测试工具使用 https://github.com/intel-cloud/cos ...
- Locust性能测试1--简介安装及基本使用
1. Locust简介 Locust是易于使用的分布式用户负载测试工具,旨在对网站(或其他系统)进行负载测试,并弄清一个系统可以处理多少个并发用户,Locust翻译过来是蝗虫的意思,在测试期间,意在一 ...
随机推荐
- 解决jenkins下使用HTML Publisher插件后查看html报告显示不正常 以jmeter报告为例
jenkins 配置使用html publisher查看jmeter html报告时,发现显示不全,很多东西显示不了. 项目配置: 查看html报告异常(很多资源无法加载): 控制台查看加 ...
- [leetcode-496-Next Greater Element I]
You are given two arrays (without duplicates) nums1 and nums2 where nums1's elements are subset of n ...
- 青出于蓝而胜于蓝 — Vue.js对Angular.js的那些进步
Angular.js与Vue.js是非常有渊源的两款前端框架,据Vue.js的官方网站描述,在其早期开发时,灵感来源就是Angular.js.而在很多方面,Vue.js也正像是中国的那句古话,&quo ...
- RADIUS and IPv6[frc-3162译文]
如今项目中需要涉及到RADIUS及IPv6的使用,而网络中的资料相对较少,现对frc-3162进行中文翻译,分享出来. 由于英语水平有限,翻译不恰当的地方,还请提出,便于在下及时修改. 原文链接 这份 ...
- maven多模块项目聚合
参考文档: http://kyfxbl.iteye.com/blog/1680045 http://blog.csdn.net/wanghantong/article/details/36427411 ...
- 关于TRIM的优化技巧
背景 今天在论坛中,看到有人在问一个千万级别表查询的优化.一个简单的查询几分钟.语句如下 SELECT work_date , major , style , ...
- epii.js简约而不简单的JS模板引擎
epii.js是什么 epii.js是一个 模板引擎,可快速实现数据与ui绑定,快速实现事件绑定,与处理,不依赖任何第三方库,仅仅8k,在native+webapp开发 和 web开发,h5微网页上均 ...
- 【TensorFlow入门完全指南】模型篇·逻辑斯蒂回归模型
import库,加载mnist数据集. 设置学习率,迭代次数,batch并行计算数量,以及log显示. 这里设置了占位符,输入是batch * 784的矩阵,由于是并行计算,所以None实际上代表并行 ...
- C/C++中static的用法全局变量与局部变量
1.什么是static? static 是C/C++中很常用的修饰符,它被用来控制变量的存储方式和可见性. 1.1static的引入 我们知道在函数内部定义的变量,当程序执行到它的定义处时,编译器为它 ...
- xdu_1064:Desolator in RA2
问题转化为,单个面积*2-交面积.下面求交面积.把直角坐标系中全部转90°,每个方块的坐标都做相应变化,这样会发现新的坐标系中空出了一部分方块,找规律发现,若求交矩形包含的方框数,其中恰好一半是前面空 ...