我想模拟两个用户同时运行不同的任务。如何使用locust性能测试框架做到这一点?
发布于 2020-07-30 17:41:19
只需定义多个用户类:
class User1(HttpUser):
@task
def task1(self):
...
class User2(HttpUser):
@task
def task2(self):
...如果您希望用户类型之间的分布为50-50,则还需要使用偶数个用户启动Locust。
发布于 2020-07-30 10:40:07
您的蝗虫任务是随机的,根据它们的权重。因此,每个用户将以不同的顺序执行任务。
如果您希望用户执行不同的任务,您可以根据用户角色或其他逻辑来决定调用哪些函数。
class Main(TaskSet):
def setup(self):
# Login
# Get user role and decide which function to call
if user.role == 'admin':
self.admin_actions()
else:
self.other_user_actions()
def admin_actions():
# Do some admin stuff
def other_user_actions():
# Do some other stuff
@task
def random_task(self):
# Some random task that everyone does
class MyLocust(HttpLocust):
task_set = Main
wait_time = between(5, 10)https://stackoverflow.com/questions/63162526
复制相似问题