feat(server): tighten memory checks when inseting a new object. #258
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.
Before this change Dragonfly evicted items only when it was low on memory and had to grow its main dictionary.
It is not enough because in many cases Dragonfly can grow in memory even when the main dictionary does not grow.
For example, when its dictionary is less than 90% utilized but the newly added objects require lots of memory.
In addition, the dashtable could add additional segments when others had enough available slots to fill the rest of the free memory.
This change adds another layer of defense that allows evicting items even when dictionary segments are not full.
The eviction is still local with respect to a segment. On my tests it seems that it's much harder to cross maxmemory limit than before.
In addition we improved our heuristic that allowed the dashtable to grow. Now it takes into account the average bytes per item in order to
project how much memory the full table takes before adding to it new segments. This really tightens dashtable utilization.
Things to improve:
This may result in very spiky insertion/eviction patterns.
in the segment. This may result in weird artifacts where we evict just enough to be under the limit, then add and evict
again and so on.
Fixes #224 and partially addresses #256
Signed-off-by: Roman Gershman [email protected]