Skip to content

Run a server

The load test

Two k6 (opens in a new tab) scripts that play many people arriving at once: the sign-up form, then the first quarter of an hour of the people it made. For the development stack only: the sign-up script reads its codes from Mailpit. They are the part of Testing and scaling Anahita (opens in a new tab) that a server opening its doors needs (roadmap row 190); the larger test is that plan's.

What it does

Script Plays Settings
signups.js People arriving at a steady rate, each through the real form: the rules ticked, the code from their mail, typed in RATE an hour (2000), DURATION (1h), FIRST, the number the first is given (0)
first-hours.js Each of those people signing in as the web app does (OAuth with PKCE), following a few of the others, then reading the home feed and the bell every 10 to 30 seconds, opening the notifications now and then and posting a note one time in ten PEOPLE, a file of [number, profile id]; VUS (300); DURATION (13m, after 2 minutes of arriving); FOLLOWS (10)

Every person seems to come from an address of its own, sent as X-Forwarded-For from 198.18.0.0/15, the range kept for benchmarks: one network in 512 for each in turn, so that no network sends more than a few. On the development stack every hop is private and trusted, so auth-service takes the header (Registration), and its own limits, by address, by network and for the day, apply as they would to real people.

Accounts are loadtest0, loadtest1 and on, with loadtest-0@gmail.com and on as addresses: a hyphen, which no Gmail address has, and in any case the development stack's mail goes to Mailpit. signups.js stops before the first person unless Mailpit answers, and stops if the first code never reaches it.

Each script has thresholds, as row 141 (opens in a new tab) has them: 95 in 100 answers within 300 ms for a read and a second for a write, and fewer than one request in a thousand failing.

Before

  1. Keep a copy of the database:

    docker exec anahita-services-mysql-1 sh -c 'mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" \
      --single-transaction --routines --triggers --events --databases anahita' > before.sql
    
  2. Turn off the location lookup for sign-ins, which would otherwise ask an outside service about thousands of made-up addresses:

    IP_LOCATION_URL=off docker compose up -d --no-deps auth-service
    
  3. The day's cap (SIGNUP_DAILY_MAX, 200) counts in UTC: a run that crosses midnight UTC starts counting again.

Running it

From the repository's root, with k6's own image:

docker run --rm --network host -v "$PWD/scripts/loadtest:/scripts:ro" \
  grafana/k6 run -e RATE=2000 -e DURATION=1h /scripts/signups.js

Then the file of the people it made, and the second script:

docker exec anahita-services-mysql-1 sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" anahita -N -e \
  "SELECT CONCAT(\"[\", SUBSTRING(alias, 9), \",\", id, \"]\") FROM nodes WHERE alias LIKE \"loadtest%\""' \
  | paste -sd, - | sed 's/^/[/; s/$/]/' > scripts/loadtest/people.json

docker run --rm --network host -v "$PWD/scripts/loadtest:/scripts:ro" \
  grafana/k6 run -e VUS=300 /scripts/first-hours.js

people.json is ignored by git.

After

Delete what the test made, and nothing else: the development stack may be used while the test runs, so the copy from before is only for when something goes wrong.

  1. In MySQL, the test's people are the profiles whose alias begins loadtest. Delete, in one transaction: the notifications and edges to or from them or their posts; their auth_logs, oauth_authorizations, oauth_refresh_tokens and auth_accounts; the tokens and signup_requests for loadtest-%@gmail.com; the day's signup_days row and the signup_notices the test sent; then their posts, and the profiles. Count first that nothing of theirs reaches anybody else's.
  2. In Valkey, the keys that were not there before (--scan, before and after), apart from the sessions of anybody else (person_sessions:<id>).
  3. In Mailpit, the messages with loadtest- in their subject. Mailpit keeps 500 messages, so older mail is gone after a long run.
  4. Start auth-service again as it was: docker compose up -d --no-deps auth-service.

Results

Run on 2026-12-05, on the development stack on one Mac (Docker Desktop, 12 GB for its machine). Every threshold held.

Sign-ups: 2,000 in an hour, through the form, each from its own address.

What Result
Accounts made 200, the day's cap, reached 6 minutes in
Waiting for approval 1,803, every sign-up after the cap, with its code confirmed
Refused, failed or with no code none, of 10,002 requests
Mail to administrators two: "made today's 200 accounts" at the cap, and one when the queue stopped being empty
The form, opened (95 in 100) 9 ms
The form, sent (95 in 100) 110 ms; the mail server checked for each address
The code, confirmed (95 in 100) 20 ms
From sending the form to the code in Mailpit 103 ms on average
100 approved at once, in the queue 0.86 s

The first quarter of an hour: 300 people, arriving over 2 minutes, each following 10 of the others, then reading the home feed and the bell every 10 to 30 seconds: 33,726 requests, 36 a second.

Request 95 in 100 within
GET /feeds/leaders/ 64 ms
GET /notifications/ 36 ms
GET /notifications/unread-count 4 ms
POST /notes/:owner_id/ 58 ms
POST /socialgraph/:id/followers/:viewer 43 ms

MySQL used about 80% of one core while the 300 were reading, and two cores for a moment while they arrived and followed one another; graph-grpc-service about a quarter of one; every other service less. The query that took most of MySQL's time is the graph's check of who may see each post, about 12 ms each time and 25,000 times: the place to look first in row 141 (opens in a new tab).

Found and fixed: following somebody already followed answered 500 (52 times in the first run, when a person happened to pick the same one twice); it now answers as the first follow did. The second run had no failure.

Where the code is

Path What
scripts/loadtest/lib.js The server's address, each person's address and name, signing in
scripts/loadtest/signups.js The sign-up form
scripts/loadtest/first-hours.js The first quarter of an hour

From anahitasocial/anahita-services, 2026-12-05.

Written by Claude, reviewed by Rastin Mehr · About this