在Locust中创建一个安装步骤?

时间:2018-12-28 20:57:04

标签: python-3.x locust

你好,我正在尝试对我创建的RESTful flask应用进行一些负载平衡测试。我正在使用Locust

产生的每个用户都有一个on_start方法。我想在客户端ONCE上创建资源,并让每个“用户”任务都在查询该资源。

class UserBehavior(TaskSet):

    def on_start(self):
    """ on_start is called when a Locust start before
        any task is scheduled
    """
    self.client.post("/resources/", json=RESOURCE_1, headers=headers_with_auth)

    @task(1)
    def profile(self):
        self.client.get("/resources/", json={})

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait = 5000
    max_wait = 9000 

这将尝试为产生的每个用户创建资源。这将失败,因为资源需要唯一。

我尝试过:

class UserBehavior(TaskSet):

    def run(self, *args, **kwargs):
        self.client.post("/resources/", json=RESOURCE_1, headers=headers_with_auth)
        super().run(args, kwargs)

但这似乎也适用于每个用户。有没有一种方法可以使用self.client创建单个设置步骤?谢谢

1 个答案:

答案 0 :(得分:0)

这有效,只是在安装程序中创建了我自己的客户端,并且仅在群集产生时才调用一次

this is line 1
this is line 2
this is line 3