Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

kirillDanshin
Copy link

Signed-off-by: Kirill Danshin kirill@danshin.pro

c.ttlmu.Lock()
for k, deadBySec := range c.ttl {
if !ttlValid(deadBySec) {
delete(c.ttl, k)
Copy link

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.

Copy link
Author

@kirillDanshin kirillDanshin May 31, 2019

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()
Copy link

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?

Copy link
Author

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

Copy link

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?

Copy link
Author

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.

fastcache_ttl_timing_test.go Outdated Show resolved Hide resolved
Signed-off-by: Kirill Danshin <kirill@danshin.pro>
@kirillDanshin
Copy link
Author

Hmm, tests failed on travis, but works on all my environments. Checking out.

@valyala valyala mentioned this pull request Jun 4, 2019
@detailyang
Copy link

Hello
Any progress? @kirillDanshin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.