Throughput
easy 30 minThroughput is how much work a system finishes per second.
Video lesson · Chapter 1 of 5
Four hundred requests arrive every second
One narrow lane decides
1:15Reel coming soon
Theory
Read or listen first. About 2 min.
What it is
Throughput is the amount of work completed in a unit of time: requests, transactions, messages or megabytes per second. Only finished, successful work counts.
Latency asks how long one request takes. Throughput asks how many we can finish per second. They are different questions: a wide road does not make a single car faster.
Most systems are a chain of stages. Work cannot leave the chain faster than its narrowest stage lets it through. That stage is the bottleneck.
Why it exists
If work arrives faster than it can be finished, it piles up. Waiting times grow, callers give up and try again, and the pile grows faster. Knowing the limit before the crowd arrives is the point of measuring it.
It also tells you what to buy. Widening a stage that is not the bottleneck changes nothing at all.
A short history
1961
John Little proves a formula that had been used without proof: the average number in a system equals the arrival rate times the average time inside.
1984
Eliyahu Goldratt's novel The Goal popularises the idea that a factory runs at the speed of its bottleneck.
1985
Datamation prints "A Measure of Transaction Processing Power", prepared by Jim Gray with colleagues, a shared test for transactions per second.
1988
The Transaction Processing Performance Council is founded to stop vendors from measuring in ways that suited themselves.
1999
Dan Kegel's C10K page asks how one server can handle ten thousand clients at once.
2014
Jay Kreps reports two million small writes a second into Kafka on three machines, and describes exactly how it was measured.
Words to know
- Bottleneck
- The stage with the lowest capacity.
- Bandwidth
- The most a link could carry. Throughput is what it does carry.
- Concurrency
- How many pieces of work are in progress at the same time.
- Utilisation
- Work done divided by the most that could be done.
- Batch
- Several operations sent as one.
- Goodput
- Throughput that is useful: successful, and on time.
- Saturation
- The point where extra load only makes queues longer.
How it works
Step through the idea, or press Play.
Count. Completed, successful work per second
Understand it
Start here
The highway toll story
Imagine a highway with a toll booth. Count the cars that pass in a minute: that is throughput. How long one car needs is latency. More booths let more cars through, although each car still needs its ten seconds.
Cars, people and tonnes per minute are three throughputs of the same road. Always say what you count.
The idea
Throughput and latency, side by side
| Latency | Throughput | |
|---|---|---|
| Asks | How long for one? | How many per second? |
| Unit | ms | requests/s, MB/s, TPS |
| Better is | Lower | Higher |
| Is about | The user's experience | The system's capacity |
| Example | 200 ms per request | 1,000 requests/s |
Planning for it
- We know one server does 100 requests a second
- The sale may bring 10,000 users, each asking once a second
- 100 servers at full use, more like 143 at 70% plus one spare
- Cache what can be cached, to need far fewer
- Balance the load and rehearse it
Ignoring it
- The system does 100 requests a second
- 10,000 users arrive on sale day
- Requests pile up until memory or patience ends
- The site stops answering, and retries add more load
- Lost sales, angry customers
Units
Four kinds of throughput
Requests (RPS, QPS)
Web APIs and search. Small service: 100 to 1,000. Medium: 10,000 to 100,000. Very large: over a million.
Transactions (TPS)
Databases and payments. One transaction is all or nothing and may hold several queries.
Data (MB/s, Gb/s)
Files, video, backups. Watch bits and bytes: divide by 8.
Messages
Queues and streams. Small messages cost more per byte than large ones.
A water park has the same choice: rides per hour, litres per minute through the pipes, tickets per hour at the gate. Different activities, different rates. How requests, queries and transactions per second differ is explained in Queries per second.
Rough sizes
| Thing | About | Basis |
|---|---|---|
| Hard disk, sequential | 150 MB/s | Rule of thumb |
| SATA SSD | 500 MB/s | Near the limit of the 6 Gb/s interface |
| NVMe SSD | 3,500 MB/s | PCIe 3 drives; newer ones are faster |
| 10 Gb/s network | 1,250 MB/s | Arithmetic |
| One relational database, simple lookups | 10,000/s to plan with | Rule of thumb, can go further |
| One Redis server, simple commands | 100,000/s | Redis docs show a benchmark near 180,000 |
| Kafka, three machines | 2 million small messages/s | Published 2014 test, 100-byte messages, 6 partitions |
| RabbitMQ, one queue | tens of thousands/s | Rule of thumb, depends on durability |
Limits
Bandwidth is not throughput
Throughput: what flows
- The cars that really pass
- "Right now we push 3 Gb/s"
- Measured
Bandwidth: what could flow
- The number of lanes
- "This link can carry 10 Gb/s"
- A property of the link
What a link allows
Factors
Five things that set it
A toy factory makes as many toys as its workers (concurrency), its doors (bottleneck), its machines (processing power) and its materials (starved resources) allow. The weakest one wins.
- 1
Concurrency
Four workers do up to 4 times the work of one, if they have cores to run on and do not wait for the same lock.
- 2
Bottlenecks
A fast API at 10,000 a second in front of a database at 100 a second is a system at 100 a second.
- 3
Resource limits
CPU 85%, memory 60%, disk I/O 95%: the disk is the one to look at.
- 4
Network bandwidth
Large answers fill the link long before the CPU is busy.
- 5
Connection pool
10 connections, each doing 50 requests a second (20 ms each), allow 500 a second.
The narrowest stage decides
Throughput of a chain
Find the bottleneck
The law
Little's law
Work in progress = throughput × latency
Read it three ways
| You know | You get | Example |
|---|---|---|
| Rate and time | How many are in progress | 3,000/s × 5 ms = 15 connections busy |
| Workers and time | The most you can finish | 200 threads / 0.2 s = 1,000/s |
| Number inside and rate | The time each takes | 500 waiting / 100/s = 5 s |
Pushing past the limit
Improve
Six ways to get more through
A supermarket opens more lanes (parallel), packs similar items together (batching), keeps an express lane (fast path) and weighs the fruit in advance (work done ahead).
| Strategy | Example | Helps when |
|---|---|---|
| Parallel processing | Three requests of 100 ms: 300 ms in a row, 100 ms together, 3 times the throughput | Cores are idle or work waits for I/O |
| Batching | 1,000 inserts at 5 ms: 5 s. One insert of 1,000 rows: 50 ms, 100 times faster | Each call has a fixed cost |
| Caching | 1 ms from a cache, 10 ms from the database | Reads repeat |
| Load balancing | 10,000/s over 4 servers: 2,500/s each | Servers are the bottleneck |
| Async and queues | The API answers at once; two workers do the job | Spikes, and work nobody waits for |
| Connection pooling | About 50 ms to open, about 0.1 ms to borrow | Opening costs more than using |
A queue between fast and slow
Batching: share the fixed cost
One by one, or one batch
Stacking improvements, worked out
| Step | Time per request at the database | One machine | Throughput |
|---|---|---|---|
| Nothing | 10 ms connect + 10 ms query | 2 connections | 100/s |
| + Connection pool | 10 ms | 2 connections | 200/s |
| + Cache, 80% hits | only 1 request in 5 arrives | 2 connections | 1,000/s |
| + Batch two queries into one | 5 ms each | 2 connections | 2,000/s |
| + 4 machines, each with its data | the same | 8 connections | 8,000/s |
What a cache does to the store behind it
Measure
How to measure it
Sit by the road with a clicker and count cars for an hour, or count one minute and multiply by 60. Both work, and both can mislead: the minute may be unusual.
- 1
Counter
Count up forever and subtract: 1,000,000 at 60 s and 1,060,000 at 120 s is 60,000 / 60 = 1,000 requests a second.
- 2
Rate over a window
Prometheus:
rate(http_requests_total[5m])is the average over 5 minutes.irateuses only the last two samples, so it jumps more. Both handle counters that restart at zero. - 3
Sampling
Keep 1% at random: 100 a second measured means about 10,000. Good for detail, poor for rare events.
Four numbers on the dashboard (example)
Now: 1,247/s
12% above the usual for this hour.
Peak: 3,891/s
The highest so far, with its date and time.
Use: 62%
Of tested capacity. 70% is the line to act on.
Good: 98.5%
1.5% failed. Count goodput, not attempts.
Tools
| Kind | Tools |
|---|---|
| Metrics and dashboards | Prometheus, Grafana |
| APM | Datadog |
| Load testing | wrk, ab, k6, Locust, JMeter |
| Database benchmark | pgbench |
wrk -t12 -c400 -d30s http://localhost:8080/apiab -n 10000 -c 100 http://localhost:8080/apiPlan
From throughput to machines
Scale which part?
Summary
The whole topic in one minute.
Throughput is finished work per second, and the narrowest stage sets it. Find that stage, widen it, and look for the next one.
Work in progress = rate × time. With a fixed number of workers, slower work means less throughput. Parallelism, batching, caching, balancing, queues and pooling each help one kind of bottleneck.
- Throughput is finished, successful work per second.
- The narrowest stage sets it. Widen that one only.
- In progress = rate × time.
- Parallelism raises throughput without making one request faster.
- Past saturation, throughput stays flat or falls. Say no early.