首页 > 技术文章 > locust性能自动化环境配置

huc-passer 2020-10-13 11:04 原文

1、安装locust

2、在项目根目录下创建locustfile.py文件

  代码如下: 

from locust import HttpUser, TaskSet, task

class UserBehavior(TaskSet):
def on_start(self):
""" on_start is called when a Locust start before any task is scheduled """
self.login()

def login(self):
pass

@task(2)
def index(self):
self.client.get("/")

@task(1)
def profile(self):
self.client.get("/address.html")

class WebsiteUser(HttpUser):
task_set = UserBehavior
min_wait = 5000    #两次执行之间的最小间隔时间
max_wait = 9000    #两次执行之间的最大间隔时间

3、输入locust启动服务

4、打开localhost:8089,进入locust UI界面

推荐阅读