Sitecore Cache Evictions: A Silent Performance Killer
Sitecore caches are one of the most overlooked but critical components for Sitecore platform stability. The caches across both the Content Management and Content Delivery roles can have either a positive impact on performance, or a negative one if not tuned properly. The Sitecore Community Site puts it best when they state:
Sitecore uses various caches to store data, rendered presentation logic and other information in memory in order to improve performance and response time. A cache is a dictionary that keeps track of when each entry is accessed. The data that is stored for each entry depends on the cache. How the cache is used also depends on the cache.https://sitecore-community.github.io/docs/documentation/Sitecore%20Fundamentals/Caching/
The challenge with caches, is that while they offer a good performance benefit and utilize a block of memory to do so, if the flow of entries overwhelm a cache, you can get a cache eviction… or multiple cache evictions if the flow of entries keep overwhelming a cache.
Why Are Cache Evictions a Problem?
Cache evictions happen when the cache does not have enough space for the entries flowing through it. For example, a publish will impact caches and when an eviction occurs it requires a CPU intensive operation to rebuild the cache. This is where performance takes a hit. Imagine that your Content Delivery front end has a ton of cache evictions while your users are visiting the site… their load alongside CPU intensive cache rebuilding could slow down the site considerably.
The CPU intensive nature of cache rebuilding is part of the reason why you see a large CPU spike when a Sitecore instance is being spun up or restarted… its because Sitecore is building the caches and placing them in memory via intensive CPU operations.
Caches are not static and will fluctuate when an action occurs, such as new entries coming in. When you see a cache eviction, irrespective of whether it was the root cause of an issue, you need to increase your cache so the next time an event such as publish occurs, it has the space to hold the entries without causing a performance issue.
In essence, your caches may look fine (even for days), but an event occurs that uses up the cache due to the flow of entries and you need to increase the cache to accommodate for this. This is why cache tuning can be challenging.
What To Do About Cache Evictions
As stated above, its imperative to get cache evictions out of your environment.
A good rule of thumb is to ensure that you don’t have any cache evictions and leave plenty of space for the caches to fluctuate. From the Sitecore docs they recommend:
“If the size of the cache is consistently more than 80% of the maximum cache size, increase the size of the cache by 25%”.https://doc.sitecore.com/en/developers/93/platform-administration-and-architecture/tune-cache-values.html
While its easy to see the caches on a CMS, its not as obvious on the CD roles, but the caches can be reviewed as follows:
On a Content Delivery server, access to the adminstrative pages is normally not available. Sitecore saves of copy of thehttps://doc.sitecore.com/en/developers/93/platform-administration-and-architecture/tune-cache-values.html
cache.aspxpage every ten minutes in the
App_Data\diagnostics\health_monitorfolder with names such as
20200907Z.131237Zis a time stamp. You can use these snapshots instead.
Once you have the information on current cache sizes and any evictions, you should increase your cache sizes based on the aforementioned formula. For ease of control/governance, it is recommended to use an include file. Sitecore has a sample include file as follows: https://doc.sitecore.com/en/developers/101/platform-administration-and-architecture/configure-item-and-data-cache-values.html
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/"> <sitecore> <databases> <database id="web" role:require="ContentDelivery or Standalone"> <cacheSizes> <data>1000MB</data> <items>1000MB</items> </cacheSizes> </database> <database id="master" role:require="Standalone or ContentManagement"> <cacheSizes> <data>1000MB</data> <items>1000MB</items> </cacheSizes> </database> </databases> </sitecore> </configuration>
Its important to note that Sitecore has some base cache size recommendations for the primary caches on the CM and CD roles. These can be found at: https://doc.sitecore.com/en/developers/101/platform-administration-and-architecture/recommended-initial-cache-values.html