Lesson 69.4 · 4 of 5 · 4 min read · Reviewed 24 Nov 2026
Load testing an LLM system
By the end, you can
- Plan a load test for an LLM system.
- Load test without large AI bills.
Load testing an AI system is mostly about your own plumbing. The model provider has already load tested theirs.
A fake model
Build a stand-in that answers like the real API:
| Behaviour | Example settings |
|---|---|
| Latency | Time to first token 0.3 to 1.5 s; 30 to 80 tokens per second |
| Output size | Drawn from your real output length distribution |
| Errors | 1% overload, rate-limit errors past a set rate |
| Headers | Remaining-budget headers that count down |
This site’s Playground uses the same idea: every model call is simulated, so nobody pays to learn.
Traffic shapes
- Steady ramp to find the knee where latencyLatency: The time from sending a request until you get the response, or until the first token arrives when streaming. jumps
- Sudden burst to test back-pressure (68.2)
- One noisy tenant to test fairness (69.3)
- Slow clients on streamsStreaming: Receiving a response as a series of server-sent events while it is generated, instead of waiting for the whole reply. to test connection limits
What to watch
Queue depth, oldest job age, p95 time to first tokenTime to first token (TTFT): How long a user waits between sending a request and seeing the first token of the reply., error rates by type, worker count and database load.
A small real test
Finally, a short, small run against the real API confirms that your limiter matches the real limits and that your code reads the real headers. Keep it short and capped.
Key points
- Load test the parts you own (queues, limiter, workers, database) with a fake model that mimics latency and errors.
- Use realistic traffic shapes: bursts, long and short prompts, streaming and slow clients.
- Run a small, short test against the real API to confirm limits and headers, then stop.
Load test against a fake model
Find your real bottleneck at ten times today's traffic without calling a real model.
You will have: A deterministic load simulation that prints p95 latency for three traffic and worker settings.
Steps
- Run the starter: with no rate limiter, 10x traffic looks fine with enough workers.
- Add the limiter so calls start no faster than the rate limit allows.
- Compare 10x traffic with 200 and with 400 workers.
- Change rpm_limit and see which setting really moves p95.
- Write down what a short real test would still need to confirm.
Done when
- At 1x traffic, p95 latency is about one long reply (17 s): no queueing.
- At 10x, p95 is very high and almost the same with 200 or 400 workers.
- You can name the rate limit, not worker count, as the bottleneck.
Open in the Playground No API key needed.
Starter code (Python)
# Load test your own system against a fake model: no real calls, deterministic timing.
import heapq
import random
def fake_model_seconds(out_tokens):
return 0.6 + out_tokens / 50 # illustrative TTFT plus generation time
def traffic(scale):
rng = random.Random(7)
events = []
for sec in range(120):
per_sec = (6 if 30 <= sec < 45 else 2) * scale # a burst between 30 s and 45 s
for k in range(per_sec):
events.append((sec + k / per_sec, rng.choice([80, 200, 400, 800])))
return events
def run(scale, workers, rpm_limit):
free = [0.0] * workers # when each worker is next free
heapq.heapify(free)
next_allowed, latencies = 0.0, []
for arrive, out_tokens in traffic(scale):
worker_free = heapq.heappop(free)
# TODO: a call may not start before next_allowed; then push next_allowed on by 60 / rpm_limit
start = max(arrive, worker_free)
end = start + fake_model_seconds(out_tokens)
heapq.heappush(free, end)
latencies.append(end - arrive)
latencies.sort()
return latencies[int(0.95 * len(latencies)) - 1]
for scale, workers in ((1, 40), (10, 200), (10, 400)):
p95 = run(scale, workers, rpm_limit=600)
print(f"{scale:>2}x traffic, {workers:>3} workers: p95 latency {p95:,.0f} s")
Show a solution
# Load test your own system against a fake model: no real calls, deterministic timing.
import heapq
import random
def fake_model_seconds(out_tokens):
return 0.6 + out_tokens / 50 # illustrative TTFT plus generation time
def traffic(scale):
rng = random.Random(7)
events = []
for sec in range(120):
per_sec = (6 if 30 <= sec < 45 else 2) * scale # a burst between 30 s and 45 s
for k in range(per_sec):
events.append((sec + k / per_sec, rng.choice([80, 200, 400, 800])))
return events
def run(scale, workers, rpm_limit):
free = [0.0] * workers # when each worker is next free
heapq.heapify(free)
next_allowed, latencies = 0.0, []
for arrive, out_tokens in traffic(scale):
worker_free = heapq.heappop(free)
start = max(arrive, worker_free, next_allowed)
next_allowed = start + 60 / rpm_limit # the rate limiter spaces out calls
end = start + fake_model_seconds(out_tokens)
heapq.heappush(free, end)
latencies.append(end - arrive)
latencies.sort()
return latencies[int(0.95 * len(latencies)) - 1]
for scale, workers in ((1, 40), (10, 200), (10, 400)):
p95 = run(scale, workers, rpm_limit=600)
print(f"{scale:>2}x traffic, {workers:>3} workers: p95 latency {p95:,.0f} s")