- 时间:2022-03-23 22:29 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:Python 3.6 性能测试框架Locust安装及使用方法(详解)
[b]
背景[/b]
Python3.6 性能测试框架Locust的搭建与使用[b]
[/b]
[b]基础[/b]
python版本:python3.6
开发工具:pycharm
[b]Locust的安装与配置[/b]
点击“File”→“setting”
[img]http://files.jb51.net/file_images/article/201710/201710110952585.png[/img]
点击“setting”,进入设置窗口,选择“Project Interpreter”
[img]http://files.jb51.net/file_images/article/201710/201710110952586.jpg[/img]
点击“+”
[img]http://files.jb51.net/file_images/article/201710/201710110952587.jpg[/img]
输入需要“Locust”,点击“Install Package”
[img]http://files.jb51.net/file_images/article/201710/201710110952588.png[/img]
安装完成即可使用。
安装完Locust工具后,只需要编写一个简单Python文件即可对系统进行负载测试。下面举个例子:
from locust import Locust, TaskSet, task
class UserBehavior(TaskSet):
@task
def job(self):
pass
class User(Locust):
task_set = UserBehavior
min_wait = 1000
max_wait = 3000
然后在终端输入:
mars@mars-Ideapad-V460:~/test$ locust
[2015-09-12 10:46:36,876] mars-Ideapad-V460/INFO/locust.main: Starting web monitor at *:8089
[2015-09-12 10:46:36,919] mars-Ideapad-V460/INFO/locust.main: Starting Locust 0.7.3
然后在浏览器中访问localhost:8089,弹出如下页面:
[img]http://files.jb51.net/file_images/article/201710/201710110952589.png[/img]
第一行Number of users to simulate是模拟用户的数量,第二行Hatch rate (users spawned/second表示产生模拟用户的速度,所有用户产生完后开始测试统计,填写完成后点击“Start swarming”即可开始测试:
[img]http://files.jb51.net/file_images/article/201710/2017101109525810.png[/img]
以上这篇Python 3.6 性能测试框架Locust安装及使用方法(详解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程素材网。