Predict the output
Without jitter, how many of the 1,000 keys expire in the busiest second?
ttls = [60 for _ in range(1000)]
print(max(ttls.count(t) for t in set(ttls)))Hint 1 of 1
How many distinct TTL values are there?
Choose an answer, then open Show answer below to check it.
Run on Redis 7
Text version
| Second | Keys expiring |
|---|---|
| 60 | 1,000 |
| Second | Keys expiring |
|---|---|
| 55 | 82 |
| 56 | 99 |
| 57 | 77 |
| 58 | 110 |
| 59 | 102 |
| 60 | 74 |
| 61 | 92 |
| 62 | 89 |
| 63 | 91 |
| 64 | 89 |
| 65 | 95 |
Show answer
Answer: A 1000
Correct. They were written together with one TTL, so they all expire together.
Every key got the same 60-second TTL at the same time, so they all expire in the same second. Adding a small random offset to each TTL spreads the expiries out.
Why not the others?
- B
17. That's roughly 1000 / 60, as if expiries spread across the minute. - C
100. That's closer to the jittered peak. - D
1. Every key has the same TTL.