inmemory cache: research other cache libraries for better performance under high concurrency
Author: yeya24Created Oct 1, 2023Updated Sep 19, 2026
Labelsdifficulty: mediumhelp wantedcomponent: store
Is your proposal related to a problem?
Currently, we are mainly using https://github.com/hashicorp/golang-lru simplelru library for inmemory cache. It is not thread safe, so we added a lock for the whole cache https://github.com/thanos-io/thanos/blob/main/pkg/store/cache/inmemory.go#L36.
This impacts the performance a lot under high concurrency situation as each get and set operation, we need to hold the lock.
In the ideally case, we should use a thread safe cache implementation which bucketizes the whole cache into multiple buckets to improve performance under high concurrency.
Describe the solution you'd like
https://github.com/dgraph-io/ristretto might be a good candidate to check.
Source: thanos-io/thanos