Call API with given rate and constant throughput using locust load testing

52 views Asked by At

Using locust load testing framework I need to call a single HTTP GET API with given pre defined rate and the through put should be always given requests per second rate. But according to the below example the RPS is changing every time due to the API response time. How can I achieve this using locust load testing.

As an example I want to call below "/hello" API with 50 requests per second constantly

from locust import HttpUser, task

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

There are 1 answers

0
Solowalker On

Sounds like what you want is constant_pacing. This will make Locust attempt to run your task at the given rate regardless of how long it takes to execute. To hit your /hello endpoint 50 times per second constantly, your code would look like:

from locust import HttpUser, task, constant_pacing

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

which would make Locust try to run your task every second. Then you run Locust and set the number of users to 50.