Skip to content
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

Cache is not respecting the provided size #26

Closed
jaredririe opened this issue Sep 5, 2017 · 4 comments
Closed

Cache is not respecting the provided size #26

jaredririe opened this issue Sep 5, 2017 · 4 comments

Comments

@jaredririe
Copy link

I create a new cache with a size of 100MB and set the GC percentage as recommended in the readme to 20%.

cacheSize := 100 * 1024 * 1024 // 100MB
cache := freecache.NewCache(cacheSize)
debug.SetGCPercent(20)

Despite this, the cache grows like a memory leak beyond the 100MB I specified. After a few days of use, it is using ~1.2 GB, as indicated by profiling the heap. The machine has just 3 GB of memory, so this is significant.

      flat  flat%   sum%        cum   cum%
 1278.15MB 98.40% 98.40%  1278.15MB 98.40%  .../vendor/github.com/coocood/freecache.NewRingBuf /go/src/.../vendor/github.com/coocood/freecache/ringbuf.go (inline)
   13.55MB  1.04% 99.44%  1291.70MB 99.44% .../vendor/github.com/coocood/freecache.newSegment /go/src/.../vendor/github.com/coocood/freecache/segment.go (inline)
@coocood
Copy link
Owner

coocood commented Sep 5, 2017

Can you give me some detail about how the cache is used?
Does it call Clear multiple times during the usage?

@coocood
Copy link
Owner

coocood commented Sep 5, 2017

Are you sure there is only one cache created?

@jaredririe
Copy link
Author

jaredririe commented Sep 7, 2017

Are you sure there is only one cache created?

Your question prompted a deep dive into this part of the code and I realized it is possible for multiple caches to be created in a particular case. I pushed out of a fix and will monitor the memory usage over the next day. I believe this is the root cause.

@jaredririe
Copy link
Author

The fix to ensure only one cache can ever be created has been live for a day now, and the memory usage for the cache is right at the requested 100MB. Thanks for the suggestion!

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

No branches or pull requests

2 participants