Queries per second
easy 30 minQPS is how many queries arrive, or can be answered, each second.
See it run
From people and days to a rate, from the rate to a peak, and from the peak to a decision.
Operations
Users to QPS
A short-message service with 100 million daily users.
Step 1 of 5
Users
| Step | Working | Result |
|---|---|---|
| Users | assumed | 100 million |
| A day | ||
| Average | ||
| Peak | ||
| So |
100 million people a day.
Step 1: Users
def average(users, each): return users * each / 86_400def peak(users, each): return 3 * average(users, each)- Answers
- What load?
- You leave with
- Average and peak
In your head: 5 billion, take five zeros off, 50,000. Times three, 150,000. Same decision.
In the real world
The same queries per second doing real jobs. Pick one and step through it.
100,000 people wait for a sale. The average day says 50 QPS.
Step 1 of 4
The average
| Way to count | QPS |
|---|---|
| Average × 3 | 150/s |
| People / interval |
4.3 million page views a day: 50 a second, 150 at three times.
Step 1: The average
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Planning for the average
criticalThe system fails in the evening, the only time that counts.
Wrongservers(avg, 1000)Rightservers(3 * avg, 1000)Reads plus writes
majorThe sum hides which part is hard.
Wrongtotal = 11_690 # "shard it"Rightwrites, reads = 350, 35_000# one database, a cacheRequests as queries
majorOne request may make twenty.
Wrongdb_qps = rpsRightdb_qps = rps * queries_each * (1 - hits)Peak from too short a window
minorTwo queries 10 microseconds apart look like 200,000 QPS.
Wrongpeak = count / elapsed # elapsed ~ 0Rightpeak = max(per_second_buckets)
Interview tips
Formulas
- Average = daily / 86,400.
- Peak = 3 × average.
- Servers = ⌈peak / (cap × 0.7)⌉ + 1.
Memory trick: QPS
- Queries: count them.
- Per: divide by time.
- Second: 86,400 in a day.
Say
- "I assume 20 each."
- "Reads 600, writes under 1."
- "So one database."
Ask
- Does a clock bring them together?
- Reads for each write?
- Which region?