Skip to content

perf(segcache): reduce catalog write amplification with dirty flag - #408

Merged
javi11 merged 1 commit into
mainfrom
feat/segcache-reduce-disk-wear
Mar 11, 2026
Merged

perf(segcache): reduce catalog write amplification with dirty flag#408
javi11 merged 1 commit into
mainfrom
feat/segcache-reduce-disk-wear

Conversation

@javi11

@javi11 javi11 commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add an atomic.Bool dirty flag to SegmentCache; SaveCatalog() is now a no-op when the catalog hasn't changed since the last flush
  • Throttle LastAccess updates in Get() to at most once per 60 seconds — read-only traffic no longer marks the catalog dirty
  • Increase the catalogFlushLoop ticker from 10 s → 60 s

Motivation

On a 10 GB cache (~13 000 entries) the catalog.json is 1–2 MB. Writing it unconditionally every 10 s produced ~720 MB/hr of pure bookkeeping writes with zero data benefit — significant SSD wear during both idle and read-heavy periods.

Test plan

  • go test ./internal/nzbfilesystem/segcache/... — all 12 tests pass
  • TestCacheSaveCatalogAndReload confirms dirty flag is set after Put() and catalog round-trips correctly
  • Manual: rapid Get() calls within 60 s should not trigger SaveCatalog() writes (dirty stays false)
  • Manual: a Put() followed by >60 s idle should result in one catalog write, then no-ops on subsequent ticks

🤖 Generated with Claude Code

Add an atomic dirty flag to SegmentCache so SaveCatalog() is a no-op
when nothing has changed. Also throttle LastAccess updates in Get() to
at most once per 60 seconds, preventing read-only traffic from
perpetually marking the catalog dirty. Increase the catalog flush
ticker from 10s to 60s.

Together these changes eliminate the ~720 MB/hr of bookkeeping writes
that occurred unconditionally on a 10 GB cache (1-2 MB catalog.json
every 10s), reducing SSD wear to near-zero during idle periods.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@javi11
javi11 merged commit b039be0 into main Mar 11, 2026
2 checks passed
@javi11
javi11 deleted the feat/segcache-reduce-disk-wear branch March 11, 2026 14:24
yoshitaka420 pushed a commit to yoshitaka420/altmount that referenced this pull request Jun 1, 2026
…ipsilabs#408)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant