-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically resize stream info caches based on available memory #3569
Conversation
2b70ba5
to
bd84af8
Compare
5c8323e
to
b75cbc6
Compare
b75cbc6
to
eca1b83
Compare
Based on tests with a large instance, it seems that the size calculation is lower by ~25% than the actual size, i'll update the PR to make the calculation more precise (LRU cache overhead is not properly accounted for) |
i pushed a bunch of trivial adjustments to a branch |
This comment was marked as resolved.
This comment was marked as resolved.
src/EventStore.Core/Services/Storage/ReaderIndex/IndexBackend.cs
Outdated
Show resolved
Hide resolved
src/EventStore.Core/Services/Storage/ReaderIndex/IndexBackend.cs
Outdated
Show resolved
Hide resolved
hey @timothycoleman thanks for the feedback! will go through it asap. i've pushed a couple more commits for more precise calculation and also some fixes (where memory wasn't being properly released) |
433b1b1
to
ae47617
Compare
00dd72f
to
0fe2a3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this need to be rebased due to the dotnet6 upgrade?
Co-Authored-By: Timothy Coleman <timothy.coleman@gmail.com>
0fe2a3a
to
9375098
Compare
Added: Dynamically resize stream info caches based on available memory
This PR adds support for caches that can be automatically resized based on free memory. Right now only one cache is dynamic: the
StreamInfo
cache but others can be added later on. A user can still make the cache static by specifying --stream-info-cache-capacity.The rationale behind the changes is that a static cache which is scaled to free memory available on startup would not be able to efficiently deal with these scenarios:
Memory allocation ratio
The
StreamInfo
cache is a logical cache comprised of theLastEventNumber
andStreamMetadata
cache. Currently 60% of the memory allocated to the logical cache is reserved to theLastEventNumber
cache and 40% toStreamMetadata
cache (this is based on empirical testing).Cache resizer hierarchy
The cache resizers are modeled as a tree structure. When resizing caches, we specify the capacity that we wan't to allocate to the root of the tree. The children (and sub-children) will then derive their capacities based on their weights and the amount allocated to them by their parent.
Resizing algorithm
The resizing algorithm is as follows:
The 200 MB change threshold ensures that:
Resizing the caches every 10 mins ensures that:
Checking every 15 seconds ensures that:
New stats
The following stats were added under
.stats.es
:.stats.sys.totalMem
- total system memory.stats.proc.gc.fragmentation
- what percent of the heap is fragmentedTODOs in later PRs
StreamInfoCacheSize
parameter (measured in bytes) which deprecatesStreamInfoCacheCapacity
(breaking change)