-
Notifications
You must be signed in to change notification settings - Fork 178
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
initial ttl support #10
base: master
Are you sure you want to change the base?
Conversation
c.ttlmu.Lock() | ||
for k, deadBySec := range c.ttl { | ||
if !ttlValid(deadBySec) { | ||
delete(c.ttl, k) |
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.
Deleting from the map will cause increasing of internal overflow buckets inside a map, so it can produce huge gc pauses. Better to use a slice here.
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.
using slices tho will cause O(n) search in the locked section (in {S,G}etWithTTL methods)
func (c *Cache) ttlGCRoutine() { | ||
go func() { | ||
for { | ||
c.ttlmu.Lock() |
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.
Does this loop cause huge pauses?
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.
it keeps map relatively small, so in practice it works pretty fast
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.
Is it possible to store ttl inside of buckets?
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.
initially I was going to do exactly that, but it caused a lot of memcopies and increased implementation complexity. current implementation is simplified, allowing to at least introduce such features and optimize further if needed.
4787439
to
3cfc486
Compare
Signed-off-by: Kirill Danshin <[email protected]>
3cfc486
to
b5258da
Compare
Hmm, tests failed on travis, but works on all my environments. Checking out. |
Hello |
Signed-off-by: Kirill Danshin [email protected]