-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
Feature: use LFU to find hotkeys #4392
Conversation
Firstly, use access time to replace the decreas time of LFU. For function LFUDecrAndReturn, it should only try to get decremented counter, not update LFU fields, we will update it in an explicit way. And we will times halve the counter according to the times of elapsed time than server.lfu_decay_time. Everytime a key is accessed, we should update the LFU including update access time, and increment the counter after call function LFUDecrAndReturn. If a key is overwritten, the LFU should be also updated. Then we can use `OBJECT freq` command to get a key's frequence, and LFUDecrAndReturn should be called in `OBJECT freq` command in case of the key has not been accessed for a long time, because we update the access time only when the key is read or overwritten.
I'm reviewing this one @soloestoy, news soon. |
There is something I do not understand about the following function changes:
Why if
Makes sense? Thanks. |
There is another potential problem:
Please could you state exactly the problems that your PR tried to address, that is, the bugs that we had in the original implementation? We already discussed this in Hangzhou face2face but very briefly. If you could re-state what you were tying to fix, maybe we can find an alternative solution without the above problem. Thanks! |
Hi, @antirez
I also noticed that you mentioned, but it won't happen in this PR, because I didn't update The access time and counter will be updated in a explicit way, when the key is really read or overwritten.
P.S. Maybe we can rename the function I have an issue #4473 about the problem I try to address, it is that:
|
About this question, because the access time's precision is in minute, so when the So, when the |
aaa3d23
to
c9021d6
Compare
Oh ok! So the function changed semantically and no longer changes the object. It's only used to retrieve the "logical" counter at this point. Got it. I'll review again based on this observation. Yep btw a name change would be a good idea, but I can do it myself after merging your PR. I think I'll have more questions today, thanks for your replies and help! |
P.S. I just noticed that the top comment now made it clear that the function no longer updates anything. |
@soloestoy Ok I re-read the patch based on the new things, I'll surely rename a few things and update a few comments, but now it makes sense in the fundamental mechanism. However there is something that I believe is broken, not in your PR specifically, but in the way it was originally coded by me: I think we should always just decrement the value of counter, and never split it in half, because the counter is logarithmic, so actually decrementing one in a logarithmic counter, is equivalent to splitting the popularity by half. So we could use instead:
|
And... there is another interesting thing we could do after updating the above code, that is, |
Agree! |
I verified the patch experimentally (after applying the fix of just decrementing), and the hit/miss ratio is a bit better compared to the vanilla |
I merged everything here into unstable. Thanks. Not clear if I'll merge those into 4.0.3 or 4.0.4 to back port the things, I'll check better tomorrow. Thanks! |
We have added a new LFU mode for
maxmemory-policy
, but forgotconfig get
andconfig rewrite
.And I think
int
is enough for the LFU factors.Another commit about LFU: do some changes about LFU to find hotkeys
Firstly, use access time to replace the decreas time of LFU.
For function LFUDecrAndReturn,
it should only try to get decremented counter,
not update the LFU fields, we will update it in an explicit way.
And we will times halve the counter according to the times of
elapsed time than server.lfu_decay_time.
Everytime a key is accessed, we should update the LFU
including update access time, and increment the counter after
call function LFUDecrAndReturn.
If a key is overwritten, the LFU should be also updated.
Then we can use
OBJECT freq
command to get a key's frequence,and LFUDecrAndReturn should be called in
OBJECT freq
commandin case of the key has not been accessed for a long time,
because we update the access time only when the key is read or
overwritten.