perf(segcache): reduce catalog write amplification with dirty flag - #408
Merged
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
atomic.Booldirty flag toSegmentCache;SaveCatalog()is now a no-op when the catalog hasn't changed since the last flushLastAccessupdates inGet()to at most once per 60 seconds — read-only traffic no longer marks the catalog dirtycatalogFlushLoopticker from 10 s → 60 sMotivation
On a 10 GB cache (~13 000 entries) the
catalog.jsonis 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 passTestCacheSaveCatalogAndReloadconfirms dirty flag is set afterPut()and catalog round-trips correctlyGet()calls within 60 s should not triggerSaveCatalog()writes (dirty stays false)Put()followed by >60 s idle should result in one catalog write, then no-ops on subsequent ticks🤖 Generated with Claude Code