Service: Locust - EyevinnOSC/community GitHub Wiki

Locust

Locust (serviceId locustio-locust) is an open source load testing tool written in Python. In Eyevinn Open Source Cloud (OSC) it is a long-running service instance that loads your locustfile.py from a URL and serves the Locust web UI. License: MIT.

What it can do

  • Define user behaviour in plain Python code and simulate large numbers of simultaneous users against a web application or API.
  • Monitor requests per second, response times and failure rates in real time in the web UI.
  • Set the host under test, number of users and spawn rate from the UI.

Creating an instance

Locust has no dependencies on other OSC services. You need a locustfile.py hosted at a publicly accessible URL, for example a raw GitHub URL:

from locust import HttpUser, task, between

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

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

    @task(3)
    def about(self):
        self.client.get("/about")

Create the instance with create-service-instance, serviceId: "locustio-locust":

{
  "name": "myloadtest",
  "LocustfileUrl": "https://raw.githubusercontent.com/myorg/myrepo/main/locustfile.py"
}

Use wait-for-service-ready or get-instance-status, then describe-service-instance for the instance URL. With the OSC CLI:

npx -y @osaas/cli create locustio-locust myloadtest \
  -o LocustfileUrl="https://raw.githubusercontent.com/myorg/myrepo/main/locustfile.py"

Options

Option Required Type Meaning
name Yes string Name of the instance. Alphanumeric, at most 20 characters.
LocustfileUrl Yes string URL of your locustfile.py. It must be publicly accessible, for example a raw GitHub URL.

Using the instance

  1. Open the instance URL in a browser to see the Locust web UI.
  2. Enter the Host, the base URL of the system under test (for example https://api.example.com).
  3. Set the Number of users and Spawn rate.
  4. Click Start swarming.
  5. Watch requests/sec, response times and failures on the Charts and Statistics tabs.
  6. Click Stop when the test is complete.

Resources