使用 Locust 负载测试以给定速率和恒定吞吐量调用 API

问题描述 投票:0回答:1

使用 Locust 负载测试框架,我需要以给定的预定义速率调用单个 HTTP GET API,并且吞吐量应始终为给定的每秒请求速率。但根据下面的示例,由于 API 响应时间,RPS 每次都会发生变化。我如何使用 Locust 负载测试来实现这一目标。

作为示例,我想以每秒 50 个请求不断调用下面的“/hello”API

from locust import HttpUser, task

class HelloWorldUser(HttpUser):
    @task
    def hello_world(self):
        self.client.get("/hello")
load-testing locust
1个回答
0
投票

听起来你想要的是constant_pacing。这将使 Locust 尝试以给定的速率运行您的任务,无论执行需要多长时间。要持续每秒命中

/hello
端点 50 次,您的代码将如下所示:

from locust import HttpUser, task, constant_pacing

class HelloWorldUser(HttpUser):
   wait_time = constant_pacing(1)
   @task
    def hello_world(self):
        self.client.get("/hello")

这会让 Locust 尝试每秒运行你的任务。然后运行 Locust 并将用户数设置为 50。

© www.soinside.com 2019 - 2024. All rights reserved.