Learn
Lesson · Scaling Laws and Cost · What bytes cost

Compress or Not

Compressing before sending trades processor time for wire time. Setting the two total times equal cancels the size of the file completely and leaves a relation between three numbers: the link, the compressor and the ratio. Above a bandwidth of rate·(k − 1)/k, sending it raw is faster.

raw size/bw = 10 GB ÷ 125 MB/s = 80 s compressed size/rate + size/(k·bw) = 40 s + 20 s = 60 s 1/bw = 1/rate + 1/(k·bw) the size cancels out entirely bw* = rate·(k − 1)/k = 187.5 MB/s = 1 500 Mbit/s faster links send raw rate* = bw·k/(k − 1) = 166.67 MB/s slower compressors lose
Two times, and an equality with no size in it

Core ideas

What this lesson establishes

Both plans are one subtraction away from each other. The surprise is what drops out of the comparison when you set them equal.

1

The compressed plan has two stages and the raw plan has one

Raw: size/bw. Compressed: size/rate to squeeze, then size/(k·bw) to send k times fewer bytes. At 10 GB, k = 4, a 250 MB/s compressor and a 125 MB/s link that is 80 s against 40 + 20 = 60 s, so compressing wins by 1.33×. Both stages are on the critical path, which is why a fast compressor matters as much as a good ratio.

2

The size cancels out of the break-even

Set the two times equal and every term carries one factor of size, so it divides away: 1/bw = 1/rate + 1/(k·bw). How much you are moving decides how long both plans take and nothing whatever about which of them is faster. That is the single most useful thing on this page, because it means the decision can be made once for a link rather than per file.

3

A fast enough link outruns every compressor

Rearranged, the break-even bandwidth is rate·(k − 1)/k = 187.5 MB/s, or 1 500 Mbit/s. Above that the wire is quicker than the processor and compression costs time. Read the other way round, on a 125 MB/s link you would need a compressor faster than 166.67 MB/s for it to be worth doing at all.

The material

Two plans, the equality between them, and what falls out of it

Where each time comes from, the algebra that removes the file size, and the two readings of the same break-even.

Definition · The two transfer times

For a payload of size bytes, a link of bw bytes a second, a compressor running at rate bytes of input a second and a compression ratio k (so the output is size/k):

raw takes size/bw;

compressed takes size/rate + size/(k·bw).

Decompression at the far end is counted only when it is on the critical path; here the receiver stores the compressed form, so it is not.

size = 10 GB = 10 000 MB bw = 1 000 Mbit/s = 125 MB/s k = 4 rate = 250 MB/s raw 10 000 ÷ 125 = 80 s compressed squeeze 10 000 ÷ 250 = 40 s 66.7% send 2 500 ÷ 125 = 20 s 33.3% ------ 60 s verdict compress, by 80/60 = 1.33× on the wire 2.5 GB instead of 10 GB

The 66.7% is worth noticing: two thirds of the compressed plan’s time is the compressor, not the network. That is the usual shape once links are fast, and it is why the break-even is about the compressor’s throughput rather than about the ratio alone.

Setting them equal

The break-even is one equation. Write the two times, set them equal, and divide both sides by size — which is legitimate because size appears exactly once in every term.

size/bw = size/rate + size/(k·bw) divide by size: 1/bw = 1/rate + 1/(k·bw) 1/bw − 1/(k·bw) = 1/rate (1/bw)(1 − 1/k) = 1/rate bw* = rate·(k − 1)/k = 250 × 3/4 = 187.5 MB/s rate* = bw·k/(k − 1) = 125 × 4/3 = 166.67 MB/s

Two readings of one equality. Fix the compressor and you get a bandwidth: above 187.5 MB/s — 1 500 Mbit/s — raw is faster, so a datacentre link defeats this compressor and a wide-area link does not. Fix the link and you get a throughput: on 125 MB/s the compressor must beat 166.67 MB/s, and many do not.

Example · Why the same file gets a different answer on two links

Send the same 10 GB over a 10 Gbit/s link, which is 1 250 MB/s. Raw: 8 s. Compressed: 40 s to squeeze plus 2 s to send, which is 42 s. Compression is now more than five times slower, and nothing about the file changed. The file never mattered: 1 250 MB/s is above bw* = 187.5, and 125 MB/s is below it.

Where the ratio helps, and where it does not

(k − 1)/k is 1/2 at k = 2, 3/4 at k = 4 and 9/10 at k = 10, so it saturates fast. Doubling the ratio from four to eight moves the break-even bandwidth from 187.5 to 218.75 MB/s, a gain of 17%; doubling the compressor’s throughput moves it from 187.5 to 375 MB/s. When both are on offer, the faster compressor is nearly always the better trade.

That is the arithmetic behind a decade of compression libraries choosing speed over ratio. Past k = 4 or so, extra ratio buys very little on the wire and is usually paid for with a great deal of processor time, which enters the plan at full weight.

When decompression counts

If the receiver has to expand the payload before doing anything with it, the far end’s time is on the critical path and the compressed plan gains a third term, size/(k·drate) in the compressed domain. The equality is the same shape with that term added to the per-byte cost, and it moves the break-even against compression. Whether it applies is a question about what the receiver does, and it should be answered before the arithmetic rather than after.

One units caution, because it causes more wrong answers here than the algebra does. Links are quoted in bits a second and payloads in bytes, so a 1 000 Mbit/s link is 125 MB/s and a factor of eight separates them. On this course MB/s is 10⁶ bytes a second and Mbit/s is 10⁶ bits a second, and the lab divides by eight rather than leaving it to be remembered.

Interactive

Compress or not

A fast enough link outruns every compressor

Compress or notthe size cancels out; the link speed decides
sent rawsqueezesendexpand, and the break-even

Method

Deciding whether to compress a transfer

Times first so the sizes are concrete, then the break-even so the answer generalises.

1

Put the link and the compressor in the same units

Bytes a second for both. A 1 000 Mbit/s link is 125 MB/s, and a compressor quoted in MB/s is already there. Most wrong answers on this page are a factor of eight.

2

Time both plans at the size you actually have

size/bw against size/rate + size/(k·bw). Keep the two stages of the compressed plan separate, because their shares tell you which of the two inputs to improve.

3

Solve the equality and report bw*

rate·(k − 1)/k. This is the number worth carrying away, because it is about the link and the compressor rather than about the file, and it answers the question for every transfer over that link.

4

State the same break-even as a compressor throughput

bw·k/(k − 1). It is the form a library is chosen against: on a 125 MB/s link, anything slower than 166.67 MB/s is making the transfer worse however good its ratio is.

5

Decide whether the far end is on the critical path

If the receiver must expand before it can act, add its time and redo the comparison. If it stores or forwards the compressed bytes, do not — and say which of the two you assumed.

Times, links and break-evens

Score 0 / 0

10 GB over a gigabit link, compressing 4× at 250 MB/s

The receiver stores the compressed form, so decompression is not on the critical path here.

size 10 GB = 10 000 MB bw 1 000 Mbit/s = 125 MB/s k = 4 rate 250 MB/s raw 10 000 ÷ 125 = 80 s compressed squeeze 10 000 ÷ 250 = 40 s send 2 500 ÷ 125 = 20 s total = 60 s verdict compress, 80/60 = 1.33× faster on the wire 2.5 GB break-even: size/bw = size/rate + size/(k·bw) 1/bw = 1/rate + 1/(k·bw) size gone bw* = rate·(k − 1)/k = 250 × 3/4 = 187.5 MB/s = 1 500 Mbit/s rate* = bw·k/(k − 1) = 125 × 4/3 = 166.67 MB/s the same file on a 10 Gbit/s link (1 250 MB/s): raw 10 000 ÷ 1 250 = 8 s compressed 40 + 2 = 42 s verdict send it raw, by 5.25×

The line where size disappears is the whole lesson. It means the two blocks at the top and bottom did not need to be computed twice: 125 MB/s is below bw* = 187.5 and 1 250 MB/s is above it, and that single comparison decides both cases for every file of every size.

The 66.7% share of the compressed plan that is the compressor is why rate* is the more actionable form. Ratio is easy to shop for and throughput is the thing that actually moves the break-even: doubling k from four to eight raises bw* by 17%, and doubling rate doubles it.

For a faded attempt, keep the gigabit link and take a slower, stronger compressor: k = 10 at 60 MB/s. Predict from rate* alone which way the verdict goes before timing anything, then compute both times and check against the lab.

Common mistakes

1
Always compressingIt is a habit from slow links and it inverts on fast ones: the same 10 GB that gains 1.33× on a gigabit link loses by 5.25× on a ten-gigabit one. The test is one comparison — is the link above rate·(k − 1)/k? — and it is answered once per link rather than once per transfer.
2
Shopping for ratio instead of throughput(k − 1)/k saturates: going from k = 4 to k = 8 moves the break-even bandwidth by 17%, while doubling the compressor’s speed doubles it. Since the squeeze is two thirds of the compressed plan here, throughput is where the time actually is.
3
Leaving the far end out when it is on the critical pathIf the receiver must expand the payload before it can act, its time belongs in the comparison and it pushes the answer toward sending raw. Omitting it is correct when the receiver stores or forwards the compressed bytes, and wrong otherwise — so the assumption has to be stated rather than inherited.

Check your understanding

✓
Finish when the compress-or-not question is answered for a link rather than for a file.

You should be able to time both plans in matching units, derive 1/bw = 1/rate + 1/(k·bw) and show the size cancelling, and report the break-even both as a bandwidth and as a compressor throughput.

Note: Shrinking the bytes is one way to make a transfer cheaper. Not transferring them is the other, and it is usually worth far more. “Move the Data or the Compute” compares shipping a dataset against shipping the job that reads it, and the comparison turns out not to contain the bandwidth at all.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.