feat: use an expiry lru cache for the index backed blockstore #1167
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
This switches over the dagstore index backed blockstore to use an expiry based LRU cache instead of just an LRU. The existing LRU will never prune unless it fills up and evicts. With the new cache, expired entries will automatically be removed, and in the event the cache hits its max size, the shards closest to expiry will be pruned first.
DealmakingConfig.BlockstoreCacheMaxShards
to set the max shards in the cache. The previous value was hard coded at100
, which the default has been set to, but we may want to lower this as it can cause process memory to grow quite large. Too low can cause in progress retrievals to fail as shards in use can be pruned.20
to match default simultaneous retrieval limitsDealmakingConfig.BlockstoreCacheExpiry
to set the duration a cached shard can be idle for until pruned, default is10 minutes
. Any time the cache is accessed it will be refreshed, so this could be set much lower if memory usage is a problem.30 seconds
Memory Usage Before
Prior to the change with retrieval load on the system, followed by allowing the system to idle, heap space increases and is not reclaimed.
Looking at a diff of the heap space allocation we can see an increase in the piece reader memory pipeline despite the system being idle.
Memory Usage After
With these changes, allowing the system to idle after retrievals we can see in use heap decrease back to pre load levels.
Performing a diff of heap utilization we can see no significant markers of memory increase...
... and a clear reduction in piece reader heap between time in load and idle time
TODO
Dependencies