Skip to content

READ-AMP-001: Leitura pode tocar múltiplos níveis L0..Ln — métrica de read amplification não exposta #370

@ElioNeto

Description

@ElioNeto

🟡 Médio | Performance | Engine/Metrics

Problema

Cada get() pode verificar MemTable + todos os níveis L0..Ln. Com bloom filter de 1% FP rate, a média é ~2.1 verificações. Sem bloom filter, pode chegar a 10+ verificações. Não há métrica de read amplification exposta.

Impacto

  • Usuários não sabem quantas SSTables estão sendo verificadas por get
  • Degradação de latência causada por níveis excessivos passa despercebida
  • Impossível dimensionar configuração de níveis baseado em dados

Evidência

src/core/engine/mod.rs:860-900: função get_cf itera níveis.
src/infra/metrics.rs: não inclui read_amplification ou levels_checked.

Correção recomendada

Adicionar ao EngineMetrics:

pub struct EngineMetrics {
    // ... existing counters ...
    pub total_get_operations: AtomicU64,
    pub total_sstable_checks: AtomicU64,
}

No get_cf:

fn get_cf(&self, cf: &str, key: &[u8]) -> Result<Option<Vec<u8>>> {
    let mut sstable_checks = 0u64;

    // Verificar MemTable
    if let Some(record) = memtable.get(key) { ... }

    // Verificar níveis
    for level in 0..=current_level {
        for table in version_set.get_tables_for_level(cf, level) {
            sstable_checks += 1;
            if table.bloom_filter.might_contain(key) {
                // ler SSTable
            }
        }
    }

    self.metrics.total_get_operations.fetch_add(1, Ordering::Relaxed);
    self.metrics.total_sstable_checks.fetch_add(sstable_checks, Ordering::Relaxed);
}

Nova métrica Prometheus:

# HELP apexstore_read_amplification_ratio Average SSTable checks per get
# TYPE apexstore_read_amplification_ratio gauge
apexstore_read_amplification_ratio 2.1

Esforço: Baixo (3h)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions