



















> The second way to solve the problem is application-level caching, which has downsides of its own, including duplicating the caching done by the page cache.
It's like anything - it depends. But I don't think application caching inherently has as many downsides as presented. Application caching has the benefit of being application and context aware about behaviour, but also likely keeping the cache in a more friendly format in memory for the application.
It's one thing to have DB pages in the FS cache, but it's another to have a deserialised struct in your application cache ready to go. If an application relied purely on FS cache, now you have to either deserialise those cache pages each operation when you read them, or you need to map your application memory structures in a way that requires binary level compatibility with what's in the FS cache to avoid a deserialise step (think mmap writing raw c structs). This has a lot of trades that application level caching simply avoids.
But the bigger reason to avoid the FS cache - memory pressure. The moment there is memory pressure, FS cache is going to be squeezed and evicted first before anything else. This leaves you far more vulnerable to fluctuations in performance if the application is on a resource contended host. This is commonly seen with k8s/docker where you may have single host with many applications. If one container relies on FS cache, and another on application cache, then we know which will be placed under cache eviction pressure first.
As an interesting upside though, if you use application cache and there is memory pressure then your own application cache may end up swapped out itself. As a result you end up with the benefits of application caching, but also the kernel able to swap in/out pages as needed when under demand, without the risks of premature eviction by relying on the FS cache. There are helpful cgroup limits too that can define how much swap you can use here in this situation as well.
So while the FS cache is extremely valuable and useful, it has a time and place to shine, but application level caching will likely always outperform the FS cache due to awareness of the use case.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。