Expand description
Batched WAL with Vectored I/O
This module implements batched WAL writing using vectored I/O (writev) to minimize syscall overhead and improve write throughput.
§Problem Analysis
Current WAL writes one entry per syscall:
- Syscall overhead: ~200-400 cycles
- Context switch potential: ~1000 cycles
- For 100K rows × 4 cols: 400K syscalls
§Solution
Batch WAL entries into single vectored write:
- Single syscall per batch (up to 1000 entries)
- Vectored I/O (writev) eliminates intermediate copies
§Math
Syscall amortization for N=100K entries, k=4 columns, B=1000 batch size:
T_unbatched = N × k × S = 100K × 4 × 300 = 120M cycles T_batched = ⌈N × k / B⌉ × S = ⌈400K / 1000⌉ × 300 = 120K cycles
Speedup: 1000× (syscall portion only)
§Performance
Expected throughput: 10-20× improvement for bulk inserts
Structs§
- Batch
Accumulator - Batch entry accumulator for a single transaction
- Batched
WalReader - Batch reader for recovery
- Batched
WalStats - Statistics for batched WAL writer
- Batched
WalWriter - Batched WAL writer with vectored I/O
- Concurrent
Batched Wal - Thread-safe batched WAL writer
Constants§
- DEFAULT_
MAX_ BATCH_ BYTES - Default maximum batch bytes (64KB)
- DEFAULT_
MAX_ BATCH_ SIZE - Default maximum batch size (number of entries)