🟡 Médio | Performance | WAL
Problema
O WAL usa batch sync a cada WAL_SYNC_INTERVAL (4) writes. Embora melhor que fsync por write, ainda está longe do throughput máximo possível. Group commit (acumular writes de múltiplos clientes antes de fsync) melhoraria throughput em ~4-10x.
Impacto
- Write throughput limitado pela frequência de fsync
- Em SSD NVMe com 100μs por fsync, máximo teórico = 4/0.0001 = 40.000 ops/s
- Com group commit (intervalo de 1ms): até 1000x mais writes por fsync
Evidência
src/storage/wal.rs:116-125: WAL_SYNC_INTERVAL = 4
src/storage/wal.rs:214-221: flush + sync_all a cada N writes
Correção recomendada
Group commit com timer:
struct GroupCommit {
pending: Arc<Mutex<Vec<PendingWrite>>>,
notifier: Arc<Condvar>,
}
impl GroupCommit {
fn submit(&self, record: LogRecord) -> Result<()> {
let mut batch = self.pending.lock();
batch.push(PendingWrite { record, result: None });
if batch.len() >= GROUP_COMMIT_BATCH_SIZE {
self.flush_batch(&mut batch);
} else {
// Timer-based: flush após 1ms se não encher antes
thread::sleep(Duration::from_millis(1));
if !batch.is_empty() {
self.flush_batch(&mut batch);
}
}
}
fn flush_batch(&self, batch: &mut Vec<PendingWrite>) {
// Serializar todos, escrever no WAL, fsync uma vez
let wal = self.wal.lock();
for write in batch.iter() {
wal.write_raw(&serialize(&write.record));
}
wal.sync_all()?; // Um fsync para N writes
batch.clear();
}
}
Parâmetros configuráveis:
GROUP_COMMIT_BATCH_SIZE: default 64 writes
GROUP_COMMIT_INTERVAL_MS: default 1ms
Esforço: Alto (12h)
🟡 Médio | Performance | WAL
Problema
O WAL usa batch sync a cada
WAL_SYNC_INTERVAL(4) writes. Embora melhor que fsync por write, ainda está longe do throughput máximo possível. Group commit (acumular writes de múltiplos clientes antes de fsync) melhoraria throughput em ~4-10x.Impacto
Evidência
src/storage/wal.rs:116-125:WAL_SYNC_INTERVAL = 4src/storage/wal.rs:214-221: flush + sync_all a cada N writesCorreção recomendada
Group commit com timer:
Parâmetros configuráveis:
GROUP_COMMIT_BATCH_SIZE: default 64 writesGROUP_COMMIT_INTERVAL_MS: default 1msEsforço: Alto (12h)