-
Notifications
You must be signed in to change notification settings - Fork 702
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
Add key-eviction-memory parameter for evicting key earlier to avoid OOM #831
base: unstable
Are you sure you want to change the base?
Conversation
e31dd8b
to
b8a98df
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #831 +/- ##
============================================
- Coverage 70.68% 70.51% -0.18%
============================================
Files 115 115
Lines 63177 63209 +32
============================================
- Hits 44657 44569 -88
- Misses 18520 18640 +120
|
b8a98df
to
ba13a0c
Compare
ba13a0c
to
e27e9de
Compare
this seem like a interesting feature, did not review, just drop a comment that approve the concept. |
I also like the idea. I just haven't really spent enough time thinking about it. Memory management is a big area in Valkey we need to improve. |
e27e9de
to
0a68013
Compare
0a68013
to
9596c78
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.
Took a quick look.
+1 on introducing "back pressure" earlier. I feel that this could be used with `maxmemory_eviction_tenacity" to give an even smoother eviction experience. |
35437eb
to
db966fe
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.
Thanks @hwware! LGTM overall. Can you add some tests too?
Sure, ready to work, Thanks |
f7cc8c8
to
7a5584b
Compare
src/evict.c
Outdated
@@ -398,11 +398,12 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev | |||
if (total) *total = mem_reported; | |||
|
|||
/* We may return ASAP if there is no need to compute the level. */ | |||
if (!server.maxmemory) { | |||
if (!server.maxmemory_available) { |
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.
Thinking about this more, I feel that it is more preferable to model this new setting as a "soft" maxmemory
, which can trigger key eviction earlier but won't cause OOM to be returned before hitting the actual maxmemory
. Otherwise, we effectively create an alias of maxmemory
. More specifically, I think performEviction
should only return EVICT_FAIL
when the memory usage goes beyond the real maxmemory
.
Additionally, since getMaxmemoryState
is also used outside of the OOM prevention path such as in VM_GetUsedMemoryRatio
, we should consider parameterizing maxmemory
and having it passed in by the caller instead, so that we can maintain the same semantics in these externally facing scenarios.
Thoughts?
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.
Like what you suggested, if we can think when "maxmemory_available" is available, it is a soft maxmemory. Then you maybe think we should not return OOM, in the case, how we can return message to client, any idea?
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.
right - how about just processing the command normally?
- if
used_memory
is below soft max, no change to the existing logic - if
used_memory
is above soft max but below hard max, trigger key eviction and continue with the normal processing - if
used_memory
is above hard max, no change to the existing logic, i.e., trigger key eviction and fail the command if theused_memory
is still above hard max after the eviction)
200b203
to
4da32a2
Compare
4da32a2
to
510265f
Compare
Yeah that makes sense.
earlier - yes; |
As the top comment describe, the feature will enable the early key eviction process, it theory, it can not make SET command faster, even make it slower (due to the eviction while loop)
Honestly said, I do not satisfy with this name either. The name origins from the https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-best-practices-memory-management. Your comment gives me a little bit hint, I would rather name it as key-eviction-memory, and the config as 'key-eviction-memory bytes'. Thus, the only relation between key-eviction-memory and maxmemory is key-eviction-memory should be less or equal to the maxmemory. It makes sense?
|
Yes, it is nice. Maybe missing a word like max, limit or threshold? |
threshold is acceptable. key-eviction-maxmemory is not good, because I thought maxmemory is pure max limit memory, and limit a little bit weird. |
I have always hoped that we could accurately measure the memory used by various different modules and then configure different thresholds and strategies, such as |
be2efd1
to
aa5d67d
Compare
@soloestoy There is already an INFO field
|
This seems to be going in a slightly different direction. My mental model so far has been a "tighter" |
Yes, I tend to use However, the current |
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: Shivshankar-Reddy <[email protected]> Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
Signed-off-by: hwware <[email protected]>
a3b5eb4
to
1e06571
Compare
Reference: #742 and https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-best-practices-memory-management (Azure)
Generally, when clients set maxmemory-policy as allkeys-lru or other memory eviction policies, and maxmemory as well, If server runs as write-heavy workloads, the data stored in memory could reach the maxmemory limit very quickly, then OOM message will be reported.
If we have maxmemory-soft-scale parameter and client enable the lazyfree-lazy feature, for example, we can set maxmemory-soft-scale as 0.8, it means key eviction begin when used memory reaches 8GB if maxmemory is 10GB, thus, server could continue process clients data and OOM will not happen at this time.
Thus, we can see the benefit is we can delay OOM time.
One example for this paramter:
Assume
maxmemory 4GB
maxmemory-soft-scale 20
Then we could check the detail by info memory command:
maxmemory:4294967296
maxmemory_human:4.00G
maxmemory_policy:allkeys-lru
maxmemory_soft_scale:20
maxmemory_soft:3435973836
maxmemory_soft_human:3.20G
We could also update and get the maxmemory-soft-scale value during runtime as following:
config set maxmemory-soft-scale value
config get maxmemory-soft-scale