Reading — step 1 of 5
Read
~1 min readStorage & Compression
Gorilla Compression
Gorilla (Facebook, 2015 paper) is the standard for TSDB compression. Key ideas:
Timestamp compression (delta-of-delta):
- First timestamp: store full 64-bit value.
- Second: store delta (D1 = T2 - T1).
- Subsequent: store delta-of-delta (DoD = (T_i - T_{i-1}) - D_{i-1}).
- Encoding:
- DoD = 0: write
0(1 bit). - DoD in [-63, 64]: write
10+ 7 bits. - DoD in [-255, 256]: write
110+ 9 bits. - DoD in [-2047, 2048]: write
1110+ 12 bits. - DoD larger: write
1111+ 32 bits.
- DoD = 0: write
For regularly-sampled data (every 10s), most DoDs are 0 → 1 bit per timestamp.
Value compression (XOR):
- First float: store full 64-bit IEEE 754.
- Subsequent: XOR with previous; encode the XORed bits.
- Encoding:
- XOR = 0: write
0. - Else: write
1+ leading_zeros (5 bits) + meaningful_bits (6 bits) + meaningful bits. - If meaningful range matches previous: skip the size header.
- XOR = 0: write
For slowly-changing values (most metrics), XORs have many leading + trailing zeros → few bits.
Combined: ~10-15 bits per (timestamp, value) pair on average. Vs raw 16 bytes (128 bits) — 10x compression.
python
Decoding is symmetric.
Blocks of 4k points are the typical size. Stream-friendly: produces a bit array; finalize closes the bit writer.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…