Load testing and sizing
One million HTTP requests with and without LazyLayers: requests per second, latency, CPU, memory and database queries, and how to turn them into an instance size.
benchmarks/api-stress.mjs sends 1,000,000 HTTP requests to a small user API twice: once through LazyLayers and once straight to the database. It reports requests per second, latency percentiles, server CPU and memory, and how many queries reached the database. This page shows the 8.0.0 result and how to turn it into an instance size.
One million callers, one query
Before the API test, the simplest stampede there is: 1,000,000 callers ask for the same missing key at the same moment.
| Run | Loader calls | Callers served that value | All served in |
|---|---|---|---|
| 10 processes sharing Redis, 100,000 callers each | 1 | 999,999 | 206.4 ms |
| One process | 1 | 999,999 | 293.8 ms |
Inside a process, callers join the load already running. Across processes, the Redis lease lets one server run the query, and the others are woken over the event bus when the value is published. inflight.maxWaiters was raised to the callers per process for this run; the default of 10,000 bounds memory and rejects callers beyond it with InflightOverloadError. Run it with npm run bench:herd-million.
The setup
- API: one
node:httpprocess,GET /users/:idthroughgetOrSet, plus 1%PUT /users/:idthat writes and then callsdelete. - Cache:
setupCachewith Redis 7 in Docker, capped at 1 CPU. L1 holds up to 20,000 entries or 64 MB. - Database: simulated, so the cost is fixed and known: a pool of 10 connections at 2 ms per query.
- Traffic: four load-generator processes, 256 keep-alive connections, user ids on a Zipf 0.99 curve over 100,000 users. Both runs start cold.
- Machine: Apple M5 (10 logical CPUs, 16 GB), Node 24.21. CPU and memory are sampled inside the server process every 250 ms.
Results
| 1,000,000 requests | LazyLayers 8.0.0 | No cache |
|---|---|---|
| Requests per second | 47,058 | 4,394 |
| Latency p50 | 2.01 ms | 58.02 ms |
| Latency p99 | 44.72 ms | 66.02 ms |
| Database queries | 98,515 | 1,000,000 |
| Server CPU per request | 16 µs | 50.1 µs |
| Server CPU, average | 75.5% of one core | 22% of one core |
| Peak RSS | 286.5 MB | 170.2 MB |
| Peak heap | 128.2 MB | 62.6 MB |
| Failed requests | 369 | 0 |
Reads were answered by L1 (726,388), Redis L2 (104,384), by joining a load already in flight (70,683), and by the database (88,363).
Raw output: benchmarks/results/8.0.0/api-stress.json. Every figure is also in BENCHMARKS.md.
Read this before quoting it
- 369 requests (0.04%) failed. Each was a read whose load raced a
PUTthat deleted the same key. The lease correctly refused to publish the old value, but the read threwDistributedLockLostErrorinstead of returning a value. With writes off, 300,000 requests had no failures. The fix is tracked for 8.1.0 in #28. Until then, if your reads can race writes to the same key, catchDistributedLockLostErrorand callgetOrSetagain. - The p99 is the cold start. The first read of each user waits for the 10-connection pool. Set
originLoad.maxConcurrentat or below your pool size so the queue sits in the cache, where it is bounded, rather than in the driver. - Production L1 entries live 10 seconds, so some reads go back to Redis even for values this process already loaded.
- One machine. The load generator shares the CPUs with the server and Redis, and the database is simulated. The numbers describe the cache and a bare HTTP handler, not your queries or your framework.
Sizing an instance
Scale the measured CPU per request to the machine you plan to use:
requests/s ≈ vCPUs × (1,000,000 ÷ CPU µs per request) × core factor × 0.7- Run one Node.js process per vCPU (cluster mode, PM2, or one ECS task per vCPU).
- CPU µs per request: 16 µs for the cache and a bare handler. Add your route's own cost: authentication, logging, the framework, serialisation.
- Core factor: how much of an Apple M5 core one cloud vCPU does. We assume 0.5 for an Arm vCPU (Graviton, Axion) and 0.4 for an x86 vCPU, which is one hyperthread. These are assumptions, not measurements.
- 0.7 keeps 30% of the CPU in reserve for spikes and garbage collection.
- Burstable machines (t3, t4g, e2-medium) count their sustained baseline, not their burst.
- Memory: about 290 MB per process with a 64 MB L1. Memory is rarely the limit; CPU is.
With the 16 µs figure alone, the estimates come out as below. The benchmarks page lists more machines.
| Instance | vCPU · RAM | Requests / s | Database queries / s | Memory |
|---|---|---|---|---|
| AWS EC2 t3.medium (20% baseline) | 2 · 4 GB | ~7,000 | ~690 | 580 MB |
| AWS EC2 m7g.large | 2 · 8 GB | ~44,000 | ~4,300 | 580 MB |
| AWS EC2 c7i.2xlarge | 8 · 16 GB | ~140,000 | ~14,000 | 2,320 MB |
| AWS ECS Fargate | 1 vCPU · 2 GB | ~18,000 | ~1,700 | 290 MB |
| Google Cloud e2-standard-2 | 2 · 8 GB | ~35,000 | ~3,400 | 580 MB |
| Google Cloud Run | 1 vCPU · 512 MiB | ~18,000 | ~1,700 | 290 MB |
The database column is what still reaches your database at that rate, using the 9.9% of requests that reached it in this run. Without a cache the database usually sets the limit, not the instance: 10 connections at 2 ms is about 5,000 queries a second on any machine.
Run it yourself
Run it on the instance you plan to use; that number replaces every estimate above.
git clone https://github.com/Amon20044/LazyLayers
cd LazyLayers && npm install
docker run -d --rm --name ll-stress-redis -p 127.0.0.1:6390:6379 --cpus 1 --memory 256m redis:7-alpine
npm run bench:api-stressChange the run with environment variables:
| Variable | Default | Meaning |
|---|---|---|
STRESS_REQUESTS | 1000000 | Requests per mode |
STRESS_MODES | lazylayers,no-cache | Which runs to make |
STRESS_KEYS | 100000 | Distinct users |
STRESS_ZIPF | 0.99 | Skew of the id distribution |
STRESS_WRITE_RATIO | 0.01 | Share of PUT requests |
STRESS_LOADERS · STRESS_CONNECTIONS | 4 · 64 | Generator processes, connections each |
STRESS_DB_POOL · STRESS_DB_MS | 10 · 2 | Simulated database pool and query time |
STRESS_L1_ENTRIES | 20000 | L1 entry limit |
STRESS_REDIS_URL | redis://127.0.0.1:6390 | Redis for L2 |
STRESS_OUTPUT | benchmarks/results/8.0.0/api-stress.json | Where the JSON goes |
Related: Prevent stampedes, Production setup, Eviction and memory.
Questions
How many requests per second can one Node.js process serve with LazyLayers?
In our run, one process served 1,000,000 requests at 47,058 per second, using 16 µs of server CPU per request and 75.5% of one Apple M5 core on average. Without a cache, the same API managed 4,394 per second because every request waited for a 10-connection database pool. Your route's own CPU adds to the 16 µs.
How much memory does LazyLayers use under load?
Peak RSS was 286.5 MB with an L1 capped at 20,000 entries and 64 MB, against 170.2 MB without a cache. Peak heap was 128.2 MB against 62.6 MB. Budget about 290 MB per process at that L1 size.
How many database queries does the cache save?
From a cold start, 1,000,000 requests made 98,515 database queries instead of 1,000,000: 90% fewer. 73.4% of reads were answered from L1, 10.5% from Redis, 7.1% by joining a load already in flight, and 8.9% by the database.
How many database queries do one million callers on one cold key cause?
One. In our run, 1,000,000 concurrent callers across 10 processes sharing Redis made one loader call, and the other 999,999 received its value within 206.4 ms. Raise inflight.maxWaiters above the default of 10,000 per process for herds that large.
Which instance size do I need?
Estimate requests per second as vCPUs × (1,000,000 ÷ CPU µs per request) × core factor × 0.7, with one Node.js process per vCPU. Measure your own route's CPU per request first, then confirm by running benchmarks/api-stress.mjs on the instance you plan to use.