Calmcode - locust: settings

How to customise behavior for Locust in Python.

1 2 3 4 5 6 7 8

The new user behavior definition is listed below:

import random
from locust import HttpUser, between, task, tag

class WebsiteUser(HttpUser):
    wait_time = between(1, 1.5)

    def on_start(self):
        self.uid = str(random.randint(0, 100_000)).zfill(6)

    @tag("attempt", "light")
    @task(2)
    def attempt(self):
        self.client.get("/hello/")

    @tag("sleep", "heavy")
    @task(3)
    def sleep(self):
        self.client.get("/sleep/")

    @tag("simulate", "light")
    @task(2)
    def simulate(self):
        self.client.post("/simulate/", json={
            "uid": self.uid,
            "n_sim": random.randint(10, 20)
        })

To run this via the terminal in headless mode you can run;

locust -f benchmark.py --headless --host http://0.0.0.0:8000 -u 1000 -r 50 --tags attempt

Note the use of the tags!