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

Multiple cachelib instances or multiple pools #93

Closed
wenhaocs opened this issue Dec 7, 2021 · 3 comments
Closed

Multiple cachelib instances or multiple pools #93

wenhaocs opened this issue Dec 7, 2021 · 3 comments

Comments

@wenhaocs
Copy link
Contributor

wenhaocs commented Dec 7, 2021

Hi, I have a question on creating cache using CacheLib.
In our scenario, we want to set up multiple caches for different objects in a single daemon. I read from the CacheLib website:

If you're using multiple cache instances, please consider if you can simplify to using a single instance via multiple cache pools. CacheLib is highly optimized for concurrency; using multiple cachelib instances is typically an anti-pattern unless you have a good reason.

If I understand correctly, if I set them as pools of the same cache instance, I can achieve a better performance than setting them as individual cache instance. Am I correct? But in this case, these pools have to use the same eviction policy, as they are added to the same cache trait (e.g., LruCacheTrait, Lru2QCacheTrait, etc.). What if I want them to have configurable eviction policies? Please advise. Thanks!

@ss7pro
Copy link

ss7pro commented Dec 7, 2021

I'm not part of Meta cachelib team but we did some benchmarking and noticed that as you add more threads to instance performance per thread goes down. This is mostly related to locks that needs to be held during evictions when you add a new item and there's not enough memory to accomodate that. So if you plan to put significant amount of load on your cache and run many threads you're better separating data types to different instances.

@haowu14
Copy link
Contributor

haowu14 commented Dec 7, 2021

Hi @wenhaocs, your understanding is correct that different pools will be using the same cache trait thus the same eviction policy.

On multiple instances vs. multiple pools: The benefit of multiple pools is that cachelib can help you balance the memory between pools. If you use multiple instances, you will need to make sure you size each instances and adjust them should your workload changes.

@wenhaocs
Copy link
Contributor Author

wenhaocs commented Dec 7, 2021

Make sense. Thanks @haowu14 @ss7pro

@haowu14 haowu14 closed this as completed Dec 7, 2021
vinser52 referenced this issue in intel/CacheLib Aug 8, 2022
Add option to print memory stats in bytes only
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

3 participants