Locust.io for load testing

Locust.io for load testing
Photo by Andile Mnothoza / Unsplash

If you are searching for a simple but effective load testing tool with a nice user interface (and it's based on python) then look no
further than locust.io.

I made an app for our microservices with locust at my job and it was really easy and cool. You can check out their <a href="https://docs.locust.io/en/stable/installation.html">docum
entation.

As always the magic incantation to install it is:

pip install locust

Write a simple class like this:

from locust import HttpUser, task, between

class QuickstartUser(HttpUser):
    wait_time = between(1, 5)

    @task
    def hello_world(self):
        self.client.get("/hello")
        self.client.get("/world")

    @task(3)
    def view_items(self):
        for item_id in range(10):
            self.client.get(f"/item?id={item_id}", name="/item")
            time.sleep(1)

    def on_start(self):
        self.client.post("/login", json={"username":"foo", "password":"bar"})

Spin up locust (with just the "locust" command), enter your configuration on the web UI and start load testing your endpoints :)