Go 中用于大量条目的快速线程安全内存缓存。最大限度地减少 GC 的开销
Fastcache performance is compared with BigCache, standard Go map
and sync.Map.
…MB/s column here actually means millions of operations per second.
As you can see, fastcache is faster than the BigCache in all the cases.
fastcache is faster than the standard Go map and sync.Map on workloads
with inserts.
The cache uses ideas from BigCache:
hash(key) -> (key, value) position map
and 64KB-sized byte slices (chunks) holding encoded (key, value) entries.
Each bucket contains only O(chunksCount) pointers. For instance, 64GB cache
would contain ~1M pointers, while similarly-sized map[string][]byte
would contain ~1B pointers for short keys and values. This would lead to
huge GC overhead.64KB-sized chunks reduce memory fragmentation and the total memory usage comparing
to a single big chunk per bucket.
Chunks are allocated off-heap if possible. This reduces total memory usage because
GC collects unused memory more frequently without the need in GOGC tweaking.
Fastcache has been extracted from VictoriaMetrics sources.
See this article
for more info about VictoriaMetrics.fastcache and other similar caches like BigCache or FreeCache?Fastcache is faster. See benchmark results above.Fastcache uses less memory due to lower heap fragmentation. This allows
saving many GBs of memory on multi-GB caches.Fastcache API is simpler.
The API is designed to be used in zero-allocation mode.fastcache doesn't support cache expiration?Because we don't need cache expiration in VictoriaMetrics.
Cached entries inside VictoriaMetrics never expire. They are automatically evicted on cache size overflow.
It is easy to implement cache expiration on top of fastcache by caching values
with marshaled deadlines and verifying deadlines after reading these values
from the cache.
fastcache doesn't support advanced features such as thundering herd protection or callbacks on entries' eviction?Because these features would complicate the code and would make it slower.
Fastcache source code is simple - just copy-paste it and implement the feature you want
on top of it.
暂无开放 Issues,或尚未同步最近议题。