Skip to content

Load testing

This directory load-tests the whole stack. The load goes through the app's /api, the harness, the agents and their models, the same way a browser's requests do. It answers Blueprint criteria C10 (response time) and C11 (concurrent users) for a given machine (Evaluation criteria). It complements harness/scripts/bench_postgres.py, which times the harness and PostgreSQL alone (Evaluation and conformance).

The models are fake (deploy/llm-gateway/scripts/testing/fake_upstream.py). Each one answers after a fixed delay, FAKE_LATENCY_MS, so: - a run costs nothing; - the results measure Data Director, not a provider's speed or rate limits.

The load is generated by Locust, in the loadtest dependency group.

File What it is
locustfile.py The simulated researcher and the pass or fail thresholds
shapes.py How many users, for how long: smoke, step, soak
prompts.py What the users send
compose.loadtest.yaml Compose overlay: the fake model, and every model-backed agent pointed at it
collect.sh Samples each container's CPU and memory into a CSV during a run

Results go to loadtest/out/, which git ignores.

What a simulated user does

Each user is one researcher with its own conversation, in a new project. The app takes one turn per conversation at a time, so several users sharing a conversation would only measure the turn lock. Between tasks it waits 2 to 8 seconds, then does one of these, weighted:

Weight Task Requests
3 Take a turn POST /api/conversations/{id}/turns
1 Take a streamed turn, as the shell does POST …/turns/stream, read to RUN_FINISHED
2 Browse GET /api/conversations, /api/projects, /api/runs, /api/conversations/{id}
1 Run example.hello directly POST /api/runs

After five turns a user starts a new conversation. Streamed turns are reported as three rows: - the request, timed to its headers; - first event; - whole run.

Setting up

Every route needs four things: 1. The fake model running. 2. The model-backed agents pointed at it. 3. A placeholder key, which the fake model accepts. 4. Optionally, the app conversing with the model-backed orchestrator.

The app converses with orchestrator.stub unless told otherwise, and the stub calls no model.

With Docker Compose

Run setup once:

uv run scripts/dd.py setup

Answer yes to PostgreSQL to measure the store a deployment uses. To converse with orchestrator.model, also: 1. Set orchestrator: model in config/local/deployment.yaml. 2. Add ANTHROPIC_API_KEY=load-test-not-a-key to config/local/agents/orchestrator-model.env. dd.py refuses a model-backed orchestrator with no key, and the overlay replaces this one anyway. 3. Write the profile:

uv run scripts/dd.py apply

Start the stack with the overlay:

FAKE_LATENCY_MS=1500 docker compose -f compose.yaml -f loadtest/compose.loadtest.yaml --profile postgres --profile llm up --build -d

The overlay points every model-backed agent at the fake model, advisor-* as well as orchestrator-model, and blanks ANTHROPIC_API_KEY_FILE and DD_MODEL_BROKER_URL. A real key in config/local/ is therefore never used, and a load test makes no provider calls. scripts/tests/test_loadtest_overlay.py fails if a model-backed agent in compose.yaml is missing from the overlay.

Then run loadtest/collect.sh alongside Locust. It writes loadtest/out/containers.csv.

On the host, without Docker

uv run scripts/dd.py setup --yes writes config/local/. Then, in config/local/:

  1. In agents.env, add ANTHROPIC_BASE_URL=http://127.0.0.1:8080.
  2. Add ANTHROPIC_API_KEY=load-test-not-a-key to the own file, agents/<name>.env, of each model-backed agent:
  3. orchestrator-model
  4. advisor-dmp, advisor-documentation, advisor-ethics, advisor-fairness, advisor-files, advisor-linking, advisor-metadata, advisor-policy, advisor-quality, advisor-repository, advisor-rights, advisor-standards, advisor-storage

The key must go in each agent's own file: dd.py refuses a key in the shared agents.env. 3. Optionally set orchestrator: model in deployment.yaml.

Then start the fake model and the stack:

FAKE_LATENCY_MS=1500 python3 deploy/llm-gateway/scripts/testing/fake_upstream.py &
uv run scripts/dd.py start --no-web --no-reload

Take the placeholder lines out again afterwards. Otherwise every model call goes to port 8080.

Checking the stack before a run

GET /api/agents should list every agent and nothing under unavailable:

curl -s http://127.0.0.1:7860/api/agents | python3 -c "import json,sys; d=json.load(sys.stdin); print(d['profile']['orchestrator'], len(d['agents']), d['unavailable'])"

Running

LOADTEST_SHAPE=smoke uv run --group loadtest locust -f loadtest/locustfile.py --headless --csv loadtest/out/smoke --html loadtest/out/smoke.html --only-summary

For step, add --csv-full-history to get a row every few seconds. Leaving out --headless opens Locust's web UI on port 8089.

LOADTEST_SHAPE Users Answers
smoke 2 for 1 minute Does it work under any concurrency at all?
step 5, 10, 20, 40, 80, each for LOADTEST_STEP_SECONDS (180) Where is the knee, where latency rises and throughput stops rising?
soak LOADTEST_USERS (20) for LOADTEST_SOAK_SECONDS (3600) Does it stay steady, or do memory, connections or locks run out?

Run soak at about 70% of the knee that step found.

Other settings: - LOADTEST_AGENT: the agent turns go to. The default is the profile's orchestrator. - LOADTEST_TURNS: turns per conversation before starting a new one (default 5). - LOADTEST_WAIT_MIN and LOADTEST_WAIT_MAX: think time in seconds. - LOADTEST_LISTERS: the weight of Lister, a user that only lists projects, conversations and runs with no think time (default 0, none). LOADTEST_LISTERS=3 makes three users in four listers. Run step with it to check that turns hold their time while listings are swamped (#1258): the app answers listings beyond DD_APP_LISTING_QUEUE with a 503, which a lister reports as … shed and not as a failure. - --host: another app. The default is http://127.0.0.1:7860.

Locust exits with code 1 in either case: - the 95th-percentile turn time (JSON or whole streamed run) is over LOADTEST_MAX_P95_MS (default 10000); - more than LOADTEST_MAX_ERROR_RATIO (default 0.01) of all requests fail.

This lets a run gate CI.

Reading the results

  • Model time: each turn's time includes FAKE_LATENCY_MS once for every model call. orchestrator.model makes one call per reply, and one more for the title on a conversation's first turn. So with 1500 ms a turn cannot take less than about 1.6 s, or about 3.1 s for a first turn. The time above that floor is Data Director's. A step run with FAKE_LATENCY_MS=0 measures that time on its own.
  • The knee: with --csv-full-history, plot step_stats_history.csv, turn p50 and p95 against User Count. The knee is where Requests/s stops rising while latency starts to.
  • 409 turn conflict: turns contending for a conversation. It should not happen, because each user has its own conversation.
  • Where to look first:
  • The app is one uvicorn process (app/src/dd_app/app.py). Turns run in its thread pool.
  • The PostgreSQL pool has DD_POSTGRES_POOL_SIZE connections (default 10).
  • In deployment, nginx times out a request after 180 s (deploy/nginx/data-director.conf).

A first measurement

The test machine: - the host route above, with file storage, not PostgreSQL; - orchestrator.model; - FAKE_LATENCY_MS=1500; - step with 30 s steps; - a 4-vCPU cloud container, with Locust on the same machine.

Users Turn p50 Turn p95 Turns/s
5 1.7 s 1.7 s 0.4
20 1.7 s 3.2 s 1.9
40 2.1 s 3.6 s 2.4
60 2.0 s 3.6 s 2.6
80 9.2 s 12 s 2.4

Turns stayed close to the model floor up to about 40 users. Throughput then levelled off at about 2.5 turns a second, and at 80 users latency rose fourfold. Nothing failed. The list routes slowed as well: GET /api/projects averaged 0.9 s and reached 4 s as conversations and projects accumulated.

These figures describe that machine only. Repeat the measurement on the deployment's own hardware, with PostgreSQL, before quoting a capacity.

With PostgreSQL

The test machine: - the Docker Compose route, with --profile postgres and runs and projects in PostgreSQL; - orchestrator.model; - step with the default 180 s steps, once at FAKE_LATENCY_MS=1500 and once at 0, each from empty tables; - an 8-core WSL2 machine, with Locust on the same machine.

Users Turn p50 / p95, 1500 ms Turn p50 / p95, 0 ms GET /api/projects p50, 1500 ms
5 2.8 s / 3.6 s 0.45 s / 0.64 s 0.41 s
10 2.1 s / 3.5 s 0.53 s / 0.84 s 0.52 s
20 11 s / 11 s 15 s / 15 s 54 s
80 19 s / 22 s 29 s / 29 s 217 s

The knee was between 10 and 20 users, with or without the model's wait. Throughput then fell rather than levelling off, from 3.2 requests a second at 10 users to 0.4 at 20 and 40. Both runs failed the p95 threshold. With an instant model, a turn took about 0.45 s of Data Director's own time.

A 20-minute soak at 7 users with FAKE_LATENCY_MS=1500 had no failures. Turns held steady at 2.3 s p50 and 3.5 s p95, and the app's memory stayed between 570 and 760 MiB. The list routes did not hold steady: GET /api/projects rose from 0.2 s to several seconds as the stored projects grew to about 130.

Profiling located the cause (#1255): - Every listing worked out what the person may read by reading each of their projects' event logs, one query at a time (#1257). - At 20 users and over, those listings held most of the app's worker threads, so turns queued behind them. - PostgreSQL itself spent only seconds executing statements. The time went on round trips and on Python in the app.

The figures above were measured before #1257 was fixed. A listing now reads the logs of the projects that name the person in one query. A single-user probe measured the list routes against PostgreSQL 16, before and after that change. It created projects with POST /api/projects, then timed 20 requests of each route at each count, on a 4-core container with the app on the host:

Projects stored GET /api/projects p50, before after Statements per request, before after
0 or 1 3 ms 3 ms 3 2
30 81 ms 6 ms 303 2
120 248 ms 10 ms 927 2
150 291 ms 10 ms 1,107 2

GET /api/conversations and GET /api/runs went from 155 ms and 602 statements to 5 ms and 2 statements at 150 projects. Each probe project has a short log. The time still grows a little with the events read, but the number of statements does not.

A rerun of step with PostgreSQL will show how far the knee has moved. Do that, and fix the neighbouring issues (#1032, #1035, #1037), before quoting a capacity.

Profiling

To see where the app spends its time during a run, attach py-spy to its process. Under Docker Compose this needs the SYS_PTRACE capability: add cap_add: [SYS_PTRACE] to the app service in an overlay of your own, then run py-spy as root in the container:

docker exec -u root data-director-app-1 sh -c 'for p in /proc/[0-9]*; do [ "$(cat $p/comm)" = data-director ] && pid=${p#/proc/}; done; UV_CACHE_DIR=/tmp/uvc uvx py-spy dump --pid $pid'
  • py-spy record --duration 60 --format speedscope -o app.json gives a profile to open in speedscope. --idle also shows threads waiting on locks or the database.
  • py-spy dump shows what every thread is doing at that moment, including which routes hold the thread pool.
  • For PostgreSQL, start db with -c shared_preload_libraries=pg_stat_statements, run create extension pg_stat_statements, and read the view after the run.

Limits

  • No delegation: the fake model replies with text and never asks for a tool. orchestrator.model therefore answers without delegating, and the advisors are not reached through conversation turns. A fake that delegates would need a scripted tool call in fake_upstream.py.
  • Direct runs: only example.hello is run directly. Advisors need inputs built for each one.
  • Not yet in CI: the shapes have not been added to CI. A smoke run there needs the whole Compose stack built.