IO Cost Model: Algorithmic Complexity for Big Data

Concept. For data larger than RAM, total runtime is dominated by IO. Model cost as C_r × pages_read + C_w × pages_written and ignore CPU.

Intuition. With Listens at a billion rows, a full table scan reads thousands of 64 MB pages and takes minutes on disk. The CPU work to compare 4.5 > 4.0 takes negligible time. Total runtime is C_r × pages_read + C_w × pages_written.


Small Data vs Big Data: Where the Cost Sits

  • Small data (< 10 GB): count CPU operations. Everything fits in RAM, so we measure CPU costs.

  • Big data (> 100 GB): count IOs, pages read and written. IO costs dominate; CPU costs are trivial by comparison.

Key Notation for IO Costs

The IO cost formula, C_r times pages read plus C_w times pages written, with C_r and C_w (the per-page read and write costs) in orange, plus P(R) the pages in table R and T(R)=n the rows in R.

Figure 1. Cost counts page I/Os, not CPU work. Cr and Cw are the time to read or write one page; P(R) is the pages in table R and T(R) = n its row count. Every algorithm's cost is Cr × pages read + Cw × pages written.

Three Examples: Building Your Intuition

Three algorithms and their IO cost. Example 1 basic: read and write every page once, Cr times P(R) plus Cw times P(R). Example 2 multi-pass: read every page seven times and write three times, Cr times seven P(R) plus Cw times three P(R). Example 3 logarithmic: read log P(R) passes and write a tenth of the pages per row, Cr times log P(R) times P(R) plus Cw times 0.1 P(R) times T(R).

Figure 2. Three algorithms, each costed by the pages it touches. Example 1 reads and writes every page once; Example 2 makes seven read passes and three write passes; Example 3 reads log P(R) passes and writes a tenth of the pages per row. The cost is the page count; the CPU work is negligible.

The Big Picture

  1. ** Sorting at O(n log n)** - That's for CPU complexity in RAM. Paging big data is much more expensive.

  2. Count IOs: N, 2N, 3N - Paging data is what really determines runtime.

  3. Smart algorithms minimize disk access. Save one IO, and you've saved 10 million CPU/GPU operations.

Calculating Read and Write Costs

The cost of reading one page, and of an algorithm:

$$ C_r = \text{access time} + \frac{\text{page size}}{\text{scan speed}} $$

$$ \text{IO cost} = C_r \times \text{pages read} + C_w \times \text{pages written} $$

Device (2025+) Access time Scan speed Cr, one 64 MB page
RAM 100 ns 100 GB/s 0.00064 s
SSD 10 μs 5 GB/s 0.01281 s
HDD 10 ms 100 MB/s 0.65 s
Network 1 μs 10 GB/s 0.00640 s

Page size is 64 MB unless a problem says otherwise; units are decimal (1 MB = 1,000,000 bytes, 1 GB = 1,000,000,000 bytes). In practice a write can cost more than a read; unless a problem says otherwise, CS145 uses Cw = Cr.

CS145 Equations (v1.3)

Open the Equations sheet full size (PDF)