Skip to content

caching: direct-arena telemetry + oldest-eviction retention fix#837

Open
snissn wants to merge 5 commits intopr/append-only-lease-trim-pool-reusefrom
pr/direct-arena-retention-telemetry-oldest-eviction
Open

caching: direct-arena telemetry + oldest-eviction retention fix#837
snissn wants to merge 5 commits intopr/append-only-lease-trim-pool-reusefrom
pr/direct-arena-retention-telemetry-oldest-eviction

Conversation

@snissn
Copy link
Copy Markdown
Owner

@snissn snissn commented Mar 15, 2026

Summary

  • add direct append-only arena telemetry counters to DB.Stats() for pool hits, retained hits, and fresh allocations (chunks/bytes)
  • expose these counters in unified-bench -treedb-cache-stats-after-tests output
  • fix append-only direct-arena retention eviction policy to evict oldest retained chunks first (preserve newest working set)
  • add deterministic unit coverage to lock in newest-window retention behavior under cap pressure

Why

  • we needed hard evidence on direct-arena churn before making further allocator changes
  • prior retention behavior evicted from the same end it appended to, which tends to preserve older retained chunks and discard recently added ones under pressure

Evidence

Unified bench command used (full suite):

GOWORK=off make unified-bench
./bin/unified-bench -dbs treedb -profile fast -keys 500000 -progress=false -treedb-index-outer-leaves-in-vlog=true -valsize=100 -checkpoint-between-tests -treedb-force-value-pointers=false -treedb-cache-stats-after-tests -profile-dir=/tmp/optimize-reads-<ts>

Baseline log/profile: /tmp/unified-run-tele4.log, /home/mikers/tmp/perf-direct-telemetry-1773589060
This PR log/profile: /tmp/unified-run-evict-oldest-rebuilt.log, /tmp/optimize-reads-1773589496

Key deltas from post-prefix_scan counters:

  • fresh_alloc_chunks_total: 2650 -> 2645 (-0.19%)
  • fresh_alloc_bytes_total: 86835200 -> 86671360 (-0.19%)
  • retained_hit_chunks_total: 3503 -> 3511 (+0.23%)
  • retained_hit_bytes_total: 114786304 -> 115048448 (+0.23%)

Selected throughput deltas (single-run, same command):

  • Sequential Write: 4,156,111 -> 4,383,749 (+5.48%)
  • Random Write: 5,251,396 -> 5,314,813 (+1.21%)
  • Batch Write: 12,524,669 -> 12,660,427 (+1.08%)
  • Batch Write (Steady): 2,140,181 -> 2,181,933 (+1.95%)

Random-write alloc-space hotspot (getAppendOnlyDirectValueArenaChunk):

  • 20598.50kB -> 15845kB (single-run snapshot)

Validation

  • go test ./TreeDB/caching -count=1
  • go test ./cmd/unified_bench -count=1
  • go vet ./TreeDB/caching ./cmd/unified_bench

Copilot AI review requested due to automatic review settings March 15, 2026 15:48
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0172726d5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds visibility and correct retention behavior for the append-only direct value arena used by TreeDB caching, and wires the new counters into unified bench output + tests.

Changes:

  • Added process-wide telemetry counters for append-only direct arena reuse vs fresh allocations (chunks/bytes).
  • Changed retained-chunk eviction policy to evict the oldest retained chunks first (preserving the newest working set).
  • Added a deterministic unit test to lock in “newest-window” retention behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
cmd/unified_bench/main.go Includes new append-only direct arena counters in the “small/stable” cache stats output list.
TreeDB/caching/db.go Implements telemetry counters, exposes them via DB.Stats(), and updates retention eviction to FIFO/oldest-first.
TreeDB/caching/append_only_direct_writer_pool_test.go Adds unit coverage for oldest-first eviction / newest-window retention behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances observability and retention behavior for the append-only direct value arena used in TreeDB/caching, adding counters for reuse/allocation and adjusting retention eviction to prefer keeping newly produced chunks.

Changes:

  • Add global counters and DB.Stats() exports for append-only direct arena pool hits, retained hits, and fresh allocations (chunks/bytes).
  • Change appendOnlyDirectValueArena.retainChunks eviction policy to evict older retained chunks first (to keep newer chunks).
  • Extend test coverage and benchmark stat printing to include the new append-only direct arena stats.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
TreeDB/caching/db.go Adds append-only arena counters + stats export; changes retained-eviction logic to evict from the “oldest” end.
TreeDB/caching/append_only_direct_writer_pool_test.go Adds a test intended to verify “evict oldest / keep newest” retention behavior.
cmd/unified_bench/main.go Prints the newly added append-only direct arena stats in the unified benchmark output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copilot AI review requested due to automatic review settings March 18, 2026 00:00
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 848e450d12

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds telemetry for the append-only direct arena (pool hits, retained hits, fresh allocations) and fixes the retention eviction order to drop the oldest retained chunks first, preserving the newest working set under pressure.

Changes:

  • Added direct-arena allocation/reuse counters to DB.Stats().
  • Exposed the new counters in unified-bench -treedb-cache-stats-after-tests output.
  • Changed retention eviction to evict oldest-first and added a deterministic unit test for newest-window retention behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
cmd/unified_bench/main.go Adds new append-only direct arena stat keys to the unified bench cache stats output list.
TreeDB/caching/db.go Implements new atomic telemetry counters; changes retained-chunk eviction to oldest-first; exports counters via DB.Stats().
TreeDB/caching/append_only_direct_writer_pool_test.go Adds a unit test asserting oldest chunks are evicted and newest are retained under capacity pressure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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.

3 participants