安装locust和简单运用locust

locust的安装:

python3.6通过 pip 命令安装:

  安装locustio:python3 -m pip install locustio

  安装pyzmq:python3 -m pip install pyzmq(如果是以分布式队列运行locust,需要装一种通信队列的库pyzmq)

安装成功验证:

  locust --help

编写简单的性能测试脚本:

Userbehave是继承TaskSet的行为类,用来定义用户行为。task装饰器是定义行为的权重,即事件的访问频率,默认为1。该类里只有一个baidu的方法,去访问百度的根路径。

WebsiteUser类去设置性能测试的参数。task_set去指向行为类,min_wait定义接口请求的最短等待时间,max_wait定义接口请求的最短等待时间,host访问的IP或者域名。

执行简单的性能测试脚本:

cmd中先切换到脚本编写的路径,运行locust -f test.py,启动性能测试

浏览器去打开http://localhost:8089

 

Number of users to simulate是模拟用户数,Hatch rate(users spanwned/sencond)是每秒启动用户数,点击Start swarming,开始测试

原文地址:https://www.cnblogs.com/letmeiscool/p/8400242.html