---
title: Storage and I/O
heading: Disks and SSDs, access time and IOPS, Little's law and the M/M/1 queue
eyebrow: S4 · Lesson 44 · Storage and I/O
xp: 50
---

::: hook
Storage is where computers wait longest: a random read from a hard disk takes about ten million cycles, and even a flash SSD takes tens of thousands. Its performance is measured in operations per second and in response time, and response time depends on far more than the device's speed: as requests arrive faster, they queue, and the wait grows without bound as the device approaches full utilization. Queueing theory, starting from Little's law and the M/M/1 model, explains why storage and network systems are run well below 100% busy, and why averages hide the latency users actually feel.
:::

::: play
- Mean response time of an M/M/1 queue (random arrivals, one server with random service times) in units of the service time S, against utilization ρ: $\frac{T}{S} = \frac{1}{1 - \rho}$.
- At 50% utilization a request takes twice its service time; at 90%, ten times; near 100%, the queue grows without bound.
- The dashed curve is the average number of requests in the system, $\frac{\rho}{1 - \rho}$ (Little's law: arrival rate × response time).
:::
:::

```sim plot
view: graph
x: r = 0..0.98
y: T = 0..30
plot: 1/(1 - r) | samples: 400 | label: response time ÷ service time
plot: r/(1 - r) | samples: 400 | dashed | color: ch2 | label: requests in the system
```

::: predict
## A disk serves a request in 10 ms on average, and requests arrive at random, 90 a second. What's the average response time?

- [ ] 10 ms
- [ ] 11 ms
- [ ] 20 ms
- [x] 100 ms

::: reveal
The disk is busy 90 × 10 ms = 90% of the time, so by the M/M/1 model the response time is 10 ms / (1 − 0.9) = 100 ms, ten times the service time, and on average 9 requests are waiting or in service. At 50 requests a second (50% busy) it would be 20 ms. Pushing utilization up buys a little throughput at a steep cost in latency.
:::
:::

::: nameit
## Devices

- **Hard disk:** access time = seek + rotational latency + transfer + controller overhead. Average rotational latency is half a revolution, $\frac{0.5 \times 60}{\text{RPM}}$ s. Random small reads are dominated by seek and rotation (about a hundred per second); sequential transfers run at hundreds of MB/s.
- **Flash SSD:** reads in tens of microseconds; writes go to erased pages, and erasure works on whole blocks, so the drive remaps writes and garbage-collects. **Write amplification** (physical writes ÷ host writes) wears the cells, each good for a limited number of program/erase cycles. Lifetime ≈ capacity × P/E cycles ÷ (daily host writes × write amplification).
- **IOPS** = 1 / access time for a device serving one request at a time; parallel devices (SSDs, arrays) serve several.

## Queueing

- **Little's law** (any stable system): $L = \lambda T$, the average number in the system equals arrival rate × average time in it.
- **Utilization** $\rho = \lambda S$ for arrival rate λ and mean service time S.
- **M/M/1** (Poisson arrivals, exponential service, one server):

$$T = \frac{S}{1 - \rho}, \qquad T_\text{queue} = \frac{S\rho}{1 - \rho}, \qquad L = \frac{\rho}{1 - \rho}$$

- To keep the mean response time below a target T: $\lambda \le \frac{1 - S/T}{S}$.
:::

::: example
## A 7200 RPM disk has an 8 ms average seek and transfers at 200 MB/s. How long does a random 4 KB read take, and how many can it do per second?

::: solution
1. **Rotation.** Half a revolution at 7200 RPM takes 4.17 ms.
2. **Transfer.**
   $$4\ \text{KB}/200\ \text{MB/s} = 0.02\ \text{ms}$$
3. **Access time.**
   $$8 + 4.17 + 0.02 \approx 12.2\ \text{ms}$$
   so about 82 random reads per second.
4. **Compare with streaming.** Sequentially it could stream 200 MB/s, 50,000 4 KB blocks a second. Disk performance depends almost entirely on the access pattern.

**Answer:** a random 4 KB read takes about 12.2 ms, so the disk does about 82 per second.
:::
:::

::: example
## An SSD holds 1 TB, its cells tolerate 600 program/erase cycles, write amplification is 3, and the host writes 100 GB a day. How long does it last? And for the 10 ms disk, what arrival rate keeps the mean response under 25 ms?

::: solution
1. **SSD lifetime.**
   $$\frac{1000\ \text{GB} \times 600}{100\ \text{GB} \times 3} = 2000\ \text{days}$$
   about 5.5 years.
2. **Disk arrival rate.**
   $$\lambda \le \frac{1 - 10/25}{0.010\ \text{s}} = 60\ \text{requests/s}$$
   which is 60% utilization.

**Answer:** the SSD lasts about 2000 days (5.5 years), and the disk must see at most 60 requests a second.
:::
:::

::: example
## A disk serves requests in 10 ms each. What response time does an M/M/1 model predict at 60 and at 90 requests a second?

::: solution
1. **At 60 a second.** Here $\rho = 0.6$:
   $$\begin{aligned} T &= 10/(1 - 0.6) \\ &= 25\ \text{ms} \end{aligned}$$
   with 1.5 requests in the system on average.
2. **At 90 a second.** Here $\rho = 0.9$:
   $$\begin{aligned} T &= 10/(1 - 0.9) \\ &= 100\ \text{ms} \end{aligned}$$
3. **The lesson.** Adding 50% more load quadrupled the response time, which is why storage systems are run well below full utilization.

**Answer:** 25 ms at 60 requests a second and 100 ms at 90.
:::
:::

::: check
given: R = 5400 | 7200 | 10000 | 15000
answer: 0.5*60/R*1000
unit: ms
tolerance: 0.5%

## What's the average rotational latency of a {R} RPM disk?

::: right
Right. Half a revolution: {answer} ms.
:::

::: misses
- [60/R*1000] On average the sector is half a turn away.
- [any] Not yet. Half the time for one revolution.
:::
:::

::: check
given: s = 4 | 8 | 12; R = 7200 | 10000; k = 4 | 64; B = 150 | 250
answer: s + 0.5*60/R*1000 + k/1000/B*1000
unit: ms
tolerance: 0.5%

## A disk has a {s} ms average seek, spins at {R} RPM and transfers {B} MB/s. How long does a random {k} KB read take, ignoring controller overhead?

::: right
Right. Seek + half a revolution + transfer = {answer} ms.
:::

::: misses
- [s + 60/R*1000 + k/1000/B*1000] Rotational latency averages half a revolution.
- [any] Not yet. Seek, rotation and transfer.
:::
:::

::: check
given: S = 2 | 5 | 10; l = 20 | 40 | 70
answer: S/(1 - l*S/1000)
unit: ms
tolerance: 0.5%

## Requests arrive at random, {l} per second, at a device whose mean service time is {S} ms. What's the mean response time by the M/M/1 model?

::: right
Right. $\rho = \lambda S$, and $T = S/(1 - \rho)$ = {answer} ms.
:::

::: misses
- [S] Requests also wait in the queue.
- [any] Not yet. Find the utilization first.
:::
:::

::: check
given: l = 50 | 200 | 1000; T = 5 | 20 | 80
answer: l*T/1000
tolerance: 0.5%

## Requests arrive at {l} per second and each spends {T} ms in the system on average. How many are in the system on average?

::: right
Right. Little's law: $\lambda T$ = {answer}.
:::

::: misses
- [l*T] Convert milliseconds to seconds.
- [any] Not yet. Arrival rate × time in the system.
:::
:::

::: check
given: S = 4 | 8; T = 10 | 20 | 50
answer: (1 - S/T)/(S/1000)
tolerance: 0.5%

## A device's mean service time is {S} ms. What's the highest arrival rate, per second, that keeps the M/M/1 mean response time at {T} ms?

::: right
Right. $\lambda = \frac{1 - S/T}{S}$ = {answer} per second.
:::

::: misses
- [1000/S] That's 100% utilization, where the response time is unbounded.
- [any] Not yet. Solve $T = S/(1 - \lambda S)$ for λ.
:::
:::

::: check
given: C = 0.5 | 2 | 4; P = 600 | 3000; W = 2 | 4; D = 50 | 200
answer: C*1000*P/(D*W)/365
unit: yr
tolerance: 0.5%

## An SSD of {C} TB has cells rated for {P} program/erase cycles and a write amplification of {W}. The host writes {D} GB a day. How many years does it last?

::: right
Right. Capacity × cycles ÷ (daily writes × WA) = {answer} years.
:::

::: misses
- [C*1000*P/D/365] Write amplification multiplies the wear.
- [any] Not yet. Total writes the cells allow ÷ physical writes per day.
:::
:::

::: check
kind: parts
given: r = 5400 | 7200 | 15000; s = 4 | 8 | 12; t = 100 | 250

## A disk spins at {r} RPM, seeks in {s} ms on average and transfers at {t} MB/s.

::: part
answer: s + 30000/r + 4/t
unit: ms
tolerance: 0.5%

### How long does a random 4 KB read take?

::: misses
- [s + 60000/r + 4/t] The average rotational wait is half a revolution.
- [any] Seek + half a revolution + transfer.
:::
:::

::: part
answer: 1000/(s + 30000/r + 4/t)
tolerance: 0.5%

### How many can it do per second?

::: misses
- [any] One over the access time.
:::
:::
:::

::: check
kind: parts
given: S = 5 | 10; l = 20 | 50 | 80

## A server takes {S} ms per request, and requests arrive at {l} per second (M/M/1).

::: part
answer: l*S/1000
tolerance: 0.5%

### What is its utilization?

::: misses
- [any] $\rho = \lambda S$.
:::
:::

::: part
answer: S/(1 - l*S/1000)
unit: ms
tolerance: 0.5%

### What is the mean response time?

::: misses
- [S] Queueing adds waiting time.
- [any] $S/(1 - \rho)$.
:::
:::

::: part
answer: (l*S/1000)/(1 - l*S/1000)
tolerance: 0.5%

### How many requests are in the system on average?

::: misses
- [any] $\rho/(1 - \rho)$.
:::
:::
:::

::: check
kind: derivation
vars: C = 100..8000, P = 300..3000, w = 1..5, h = 10..2000

## An SSD of C GB endures P program/erase cycles with write amplification w; the host writes h GB a day.

::: step
answer: C*P

### How many gigabytes can be written to the flash in its life?
:::

::: step
answer: C*P/(w*h)

### How many days does it last?
:::

::: right
Right. Write amplification divides the life directly, which is why drives reserve spare capacity to keep it low.
:::
:::

::: explain
## Why do storage systems run far below full utilization, when a busier device does more work?

::: model
When requests arrive at random, they sometimes bunch up, and while the device works through a bunch, later arrivals wait. The busier the device, the more likely each arrival finds others ahead of it, and the queue's average length grows as ρ/(1 − ρ), so the waiting time grows without bound as utilization approaches 100%. Going from 50% to 90% utilization raises throughput by 80% but multiplies the mean response time by five, and the slowest requests, the ones users notice, get worse still. Systems that need predictable latency are therefore sized to stay at moderate utilization, and buy the throughput they need with more devices instead of busier ones.
:::
:::

::: practice

::: check
given: R = 4200 | 5400 | 7200 | 10000 | 12000 | 15000
answer: 0.5*60/R*1000
unit: ms
tolerance: 0.5%

## Rotational latency at {R} RPM?

::: misses
- [any] Half a revolution.
:::
:::

::: check
given: S = 3 | 6; l = 60 | 120
answer: S/(1 - l*S/1000)
unit: ms
tolerance: 0.5%

## M/M/1 response: service {S} ms, {l} per second?

::: misses
- [any] $S/(1 - \lambda S)$.
:::
:::

::: check
given: l = 100 | 600; T = 8 | 40
answer: l*T/1000
tolerance: 0.5%

## Little's law: {l} per second, {T} ms each?

::: misses
- [any] $\lambda T$.
:::
:::
:::
