Skip to content

perf(vindex/kvstore): enable L6 Bloom filters, partition by KeyHash, and tune Pebble backfill - #204

Merged
mhutchinson merged 1 commit into
transparency-dev:mainfrom
mhutchinson:perf/kvstore-l6-locality
Dec 1, 2026
Merged

mhutchinson merged 1 commit into
transparency-dev:mainfrom
mhutchinson:perf/kvstore-l6-locality

Conversation

@mhutchinson

Copy link
Copy Markdown
Contributor

Why

While benchmarking vindexd (ct.wasm) against Let's Encrypt Sycamore 2026h1 (926M entries, 1.48B key occurrences, 67 GB Pebble DB), ingestion throughput degraded from ~81k leaves/s early on to ~6.4–8.5k leaves/s once Pebble compacted into L6 (with active CPU collapsing from 9.5 to 2.0 cores and Syscall6 rising to 28.4%).

Two compounding issues in kvstore drove the late-stage I/O wall:

  1. L6 Bloom filters were silently bypassed: kvstore/store.go writes 10-bit table Bloom filters on all 7 Pebble levels (L0..L6), but NewIter(nil) leaves UseL6Filters: false. In Pebble v1.1.5 (table_cache.go:511), the bottommost LSM level is always L6 (~90% of a large DB), so every brand-new domain (~60% of keys per CT slab) bypassed Bloom filters and triggered a 4 KiB L6 SSTable data-block read.
  2. Random KeyHash SSTable thrashing across workers: KVIndexer.buildBatchMutations sorted and partitioned slabs by canonical key string ("com.a...") rather than SHA-256 KeyHash, causing all workers to issue random SeekPrefixGE('c' || KeyHash) jumps across the entire SSTable keyspace and stage pebble.Batch writes out of key order.

What Changed

  • Enable L6 Bloom filters: Pass pebble.IterOptions{UseL6Filters: true} on DB.Lookup and KVIndexer write-path iterators (verified via Pebble Filter.Hits in TestDB_L6BloomFiltersEnabled), keeping nil IterOptions on GetKeyValueRoots recovery replay where queried keys exist.
  • Disjoint KeyHash radix partitioning & sorted batch writes: Partition and sort KVIndexer.buildBatchMutations and GetKeyValueRoots by SHA-256 KeyHash across workers (capped at 256 workers for dense 1-byte hash[0] bucketing) so each worker scans a disjoint SSTable range monotonically forward and stages chunk writes in strictly ascending 'c' + KeyHash + ^chunkNum order.
  • Hot-path allocation cuts: Mutate warm active-chunk descriptors in place on non-staged IndexMappedBatch paths (with ClearCache() on error), reuse per-worker marshal/write buffers, validate canonical keys directly on string (wire.ValidateCanonicalKeyString), pre-size RelativeIndices, and skip slices.Clone when leaf indices are already strictly increasing.
  • Backfill defaults & tuning: Double per-generation active chunk cache (131,072 -> 262,144), raise default CommitBatchSize (4,096 -> 16,384), skip redundant ManagedTileCache in-RAM bundle cloning when TileCacheDir == "" (matching auditor.go), and expose --kv_indexer_workers, --kv_chunk_cache_size, --db_memtable_size_mb, --db_l0_compaction_threshold, and --db_max_concurrent_compactions on vindexd (with overflow guards).

Benchmarks (linux/amd64, Intel Xeon @ 2.20GHz)

Benchmark Before (main) After Delta
Lookup_AbsentKey_FlushedSSTables 5,398 ns/op (168 B, 4 allocs) 4,671 ns/op (168 B, 4 allocs) -13.5% time
IndexBatch_1000Keys/workers_1 7.35 ms/op (1,060 KB, 7,298 allocs) 6.30 ms/op (603 KB, 1,195 allocs) -14.3% time, -43.1% B, -83.6% allocs
IndexBatch_1000Keys/workers_8 5.07 ms/op (1,624 KB, 7,476 allocs) 4.53 ms/op (675 KB, 1,203 allocs) -10.6% time, -58.4% B, -83.9% allocs
ColdCache_L6SSTables/workers_1 20.83 ms/op (2,165 KB, 19,845 allocs) 18.52 ms/op (2,134 KB, 17,024 allocs) -11.1% time, -14.2% allocs
ColdCache_L6SSTables/workers_8 11.53 ms/op (2,910 KB, 20,511 allocs) 10.06 ms/op (2,404 KB, 17,944 allocs) -12.8% time (in-RAM), -17.4% B, -12.5% allocs
GetKeyValueRoots_L6SSTables 2.83 ms/op (995 KB) 2.80 ms/op (1,327 KB, sorted forward scans) Disjoint forward SSTable scans

Verification

  • go vet ./...
  • CGO_ENABLED=0 go test ./vindex/...
  • go test -race ./vindex/...

…and tune Pebble backfill

During large CT log backfills (e.g. Sycamore 2026h1 at 926M entries / 67 GB Pebble),
ingestion throughput degraded once Pebble compacted into L6 due to two compounding
issues in kvstore:

1. Missing IterOptions{UseL6Filters: true}: store.go configures 10-bit table Bloom
   filters across all 7 levels (L0..L6), but NewIter(nil) leaves UseL6Filters=false,
   causing Pebble to skip Bloom filters on L6 (which holds ~90% of the LSM) and
   read 4 KiB L6 data blocks on every absent/ephemeral key.
2. Canonical-string worker partitioning: KVIndexer sorted and partitioned slabs by
   canonical key string rather than SHA-256 KeyHash, causing every worker to issue
   random SeekPrefixGE jumps across the full [0x00..0xFF] SSTable keyspace and stage
   pebble.Batch writes out of key order.

Changes:
- Opt into UseL6Filters: true on DB.Lookup and KVIndexer iterators (retaining nil
  IterOptions on GetKeyValueRoots recovery replay where queried keys exist).
- Partition and sort KVIndexer.buildBatchMutations and GetKeyValueRoots by SHA-256
  KeyHash across workers so each worker scans a disjoint SSTable range forward and
  stages chunk writes in strictly ascending Pebble key order.
- Eliminate per-key heap clones on warm non-staged IndexMappedBatch hits, reuse
  worker marshal/write buffers, validate canonical keys directly on string, and
  skip slices.Clone when input leaf indices are already strictly increasing.
- Double default per-generation active chunk cache capacity (131,072 -> 262,144),
  raise default CommitBatchSize (4,096 -> 16,384), skip redundant in-RAM bundle
  cloning when TileCacheDir is empty, and expose KVIndexer/Pebble tuning flags on
  vindexd.

Benchmarks (linux/amd64, Intel Xeon @ 2.20GHz):
- BenchmarkLookup_AbsentKey_FlushedSSTables-24:
  5,398 ns/op -> 4,671 ns/op (-13.5%), 168 B/op -> 168 B/op, 4 -> 4 allocs/op
- BenchmarkKVIndexer_IndexBatch_1000Keys/workers_1-24:
  7,354,744 ns/op -> 6,301,465 ns/op (-14.3%), 1,060,455 B/op -> 603,012 B/op (-43.1%), 7,298 -> 1,195 allocs/op (-83.6%)
- BenchmarkKVIndexer_IndexBatch_1000Keys/workers_8-24:
  5,065,942 ns/op -> 4,529,381 ns/op (-10.6%), 1,624,022 B/op -> 675,143 B/op (-58.4%), 7,476 -> 1,203 allocs/op (-83.9%)
- BenchmarkKVIndexer_ColdCache_L6SSTables/workers_1-24:
  20,830,985 ns/op -> 17,270,191 ns/op (-17.1%), 2,164,727 B/op -> 2,105,405 B/op (-2.7%), 19,845 -> 16,911 allocs/op (-14.8%)
- BenchmarkKVIndexer_ColdCache_L6SSTables/workers_8-24:
  11,531,944 ns/op -> 10,517,247 ns/op (-8.8%), 2,910,006 B/op -> 2,403,483 B/op (-17.4%), 20,511 -> 17,840 allocs/op (-13.0%)
- BenchmarkKVIndexer_GetKeyValueRoots_L6SSTables-24:
  2,831,966 ns/op -> 2,596,947 ns/op (-8.3%)
@mhutchinson
mhutchinson requested a review from patflynn November 30, 2026 12:58
@mhutchinson
mhutchinson merged commit 3f46165 into transparency-dev:main Dec 1, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants