Skip to main content

Module batch_wal

Module batch_wal 

Source
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§

BatchAccumulator
Batch entry accumulator for a single transaction
BatchedWalReader
Batch reader for recovery
BatchedWalStats
Statistics for batched WAL writer
BatchedWalWriter
Batched WAL writer with vectored I/O
ConcurrentBatchedWal
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)