# Load testing with Locust `locustfile.py` measures how the platform behaves under concurrent traffic. It is separate from the correctness suite: it asserts nothing, it reports throughput, latency, and error rates. See also [Testing overview](/docs/testing.html) and [Running tests via make](/docs/testing-make.html). ## What it simulates A single `DevPlaceUser` class models a visitor with `wait_time = between(1, 5)` seconds between actions. Tasks are weighted so common reads happen far more often than rare writes: browsing the feed and opening posts, projects, gists, and news weigh heavily, while creating content, commenting, voting, and admin actions weigh less. On start each user registers or logs in, so authenticated flows are exercised, not just public pages. The file seeds a pool of users and content at launch (via an `events.init` listener) and harvests real slugs and UUIDs from the running site, so requests hit live resources rather than fabricated identifiers. ## Running it Both targets are self-contained: they start a dedicated Uvicorn server, wait for it to answer, run Locust against it, then stop the server and delete the throwaway database. Nothing touches the development database. ```bash make locust # interactive: opens the Locust web UI make locust-headless # CI mode: fixed users/run-time, writes an HTML report ``` `make locust` opens the web interface, where you set the user count and spawn rate and watch live charts. `make locust-headless` runs unattended with preset parameters and writes a report to the run directory. ## Configuration The targets read overridable `make` variables (shown with their defaults): | Variable | Default | Purpose | |----------|---------|---------| | `LOCUST_PORT` | `10502` | Port the load-test server binds. | | `LOCUST_WEB_PORT` | `10503` | Port the Locust web UI binds. | | `LOCUST_DB_DIR` | `/tmp/devplace_locust` | Scratch directory for the throwaway database and report. | | `LOCUST_USERS` | `20` | Simulated users (headless mode). | | `LOCUST_SPAWN_RATE` | `5` | Users started per second (headless mode). | | `LOCUST_RUN_TIME` | `120s` | Headless run duration. | | `DEVPLACE_RATE_LIMIT` | `1000000` | Rate-limit ceiling, raised so the load test is not throttled. | Override any of them inline, for example a heavier headless run: ```bash make locust-headless LOCUST_USERS=100 LOCUST_SPAWN_RATE=10 LOCUST_RUN_TIME=300s ``` ## Why a separate database The rig points `DEVPLACE_DATABASE_URL` at a fresh file under `LOCUST_DB_DIR`, removes it before the run, and removes it after. Load testing creates large volumes of synthetic users, posts, and votes; isolating it keeps that noise out of the real database and guarantees each run starts clean. ## Reading the results In the web UI, watch the requests-per-second, the response-time percentiles, and the failure count. A healthy run holds a low median latency with stable RPS and zero failures. Rising p95 latency or a climbing failure rate as users ramp marks where the platform saturates. The headless report captures the same numbers as a static HTML file for archiving or CI comparison.