GithubHelp home page GithubHelp logo

Comments (4)

Kaushal28 avatar Kaushal28 commented on June 12, 2024 3

I could find many other similar open issues/bug stating almost the same problem as I mentioned:

#311
#353
#309
#109

From all these, it seems that when over writing existing key with same value or deleting keys would not actually delete the existing value and will keep adding new content to the cache and it's intentional. So we must set max hard limit to cache size
HardMaxCacheSize. Is it right? If what I mentioned is correct and that's intentional, may I know the exact reason behind this design choice? Thanks.

@janisz

from bigcache.

janisz avatar janisz commented on June 12, 2024

You need to specify HardMaxCacheSize in order to keep memory limited. Without it cache will only grow.

bigcache/config.go

Lines 25 to 32 in caa3415

// HardMaxCacheSize is a limit for BytesQueue size in MB.
// It can protect application from consuming all available memory on machine, therefore from running OOM Killer.
// Default value is 0 which means unlimited size. When the limit is higher than 0 and reached then
// the oldest entries are overridden for the new ones. The max memory consumption will be bigger than
// HardMaxCacheSize due to Shards' s additional memory. Every Shard consumes additional memory for map of keys
// and statistics (map[uint64]uint32) the size of this map is equal to number of entries in
// cache ~ 2×(64+32)×n bits + overhead or map itself.
HardMaxCacheSize int

bigcache/config.go

Lines 57 to 67 in caa3415

func DefaultConfig(eviction time.Duration) Config {
return Config{
Shards: 1024,
LifeWindow: eviction,
CleanWindow: 1 * time.Second,
MaxEntriesInWindow: 1000 * 10 * 60,
MaxEntrySize: 500,
StatsEnabled: false,
Verbose: true,
Hasher: newDefaultHasher(),
HardMaxCacheSize: 0,

from bigcache.

Kaushal28 avatar Kaushal28 commented on June 12, 2024

@janisz, but why cache will only grow even if the number of key/value pairs is constant all the time and the content (both key and values) that I am setting again after removing is also exactly the same? I understand that there might be some additional space requirements by library itself for internal handling (overhead as mentioned in the comments of HardMaxCacheSize above) but shouldn't it remain almost constant if the key values are the same overtime? Why am I seeing GBs of fluctuations as I do more and more Set() and Removes()?

from bigcache.

Kaushal28 avatar Kaushal28 commented on June 12, 2024

I also tried the same above script with various other Go in-memory caching libraries like go-cache, ttl-cache and even the native Go maps. Non of them are showing this much fluctuation. Also, the total memory footprint is also way higher in bigcache. So I was wondering if there is any specific reason for that?

from bigcache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.