Back to Performance Test

See Also GatlingApache JMeterApacheBenchwrk

Locust

1. Quickstart

https://docs.locust.io/en/stable/quickstart.html

1.1. Writing Locust tests

from locust import HttpLocust, TaskSet, between, task

# https://docs.locust.io/en/stable/quickstart.html#example-locustfile-py
class UserBehavior(TaskSet):
    def on_start(self):
        """ on_start is called when a Locust start before any task is scheduled """
        self.login()

    def on_stop(self):
        """ on_stop is called when the TaskSet is stopping """
        self.logout()

    def login(self):
        self.client.post("/login", {"username":"ellen_key", "password":"education"})

    def logout(self):
        self.client.post("/logout", {"username":"ellen_key", "password":"education"})

    @task(2)
    def index(self):
        self.client.get("/")

    @task(1)
    def profile(self):
        self.client.get("/profile")

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    wait_time = between(5, 9)

# [Running Locust without the web UI](https://docs.locust.io/en/stable/running-locust-without-web-ui.html)
locust -f locust_files/my_locust_file.py --no-web -c 1000 --run-time 1h30m

1.2. API

https://docs.locust.io/en/stable/api.html

TaskSet

HttpLocust

HttpSession

Response

2. Reference


CategoryTool