While working with one of our clients, content authors started complaining about the page load time in experience editor. The environment was Azure IaaS. So, we started looking at all the performance tweaks we could apply.
Sitecore Cache Tuning
Performance and cache go hand-in-hand :D So first thing we wanted to explore was Sitecore caching especially the cache sizes. I assume the readers are already aware about Sitecore caches and how to configure them.
We used the showconfig.aspx (https://<my sitecore hostname>/sitecore/admin/showconfig.aspx) and looked especially for Sitecore's prefetch, items and data cache sizes.
So, how do we know if the cache sizes are sufficient for our application?
First, you need to open Cache Administration page (http://<my sitecore instance>/sitecore/admin/cache.aspx). This page lists the cache details in a tabular format and gives you runtime view of cache details.
Note: On a Content Delivery server, access to the administrative pages is normally not available. Sitecore saves of copy of the cache.aspx page every ten minutes in the App_Data\diagnostics\health_monitor folder with names such as CacheStatus.20200907Z.131237Z.html where 20200907Z.131237Z is a time stamp. You can use these snapshots instead.
Cache.aspx looks like this -
How to understand the output of cache.aspx?
The Cache Administration page reports the following details for each cache:
- Name — A unique string that identifies each cache. Sitecore cache works on collection. Suppose you are dealing with HashTable where you have Key/Value Pair. Where Key is an identifier and Value is an Object. This name indicates Key.
- Count — The number of items in the cache.
- Size — The approximate current size of the cache.
- Delta — The approximate change in the size of the cache since the last refresh of the cache administration page. In Bytes. Open page first time and then click on refresh [By clicking on Refresh button at top]. If Delta value goes in negative then it means that Sitecore removed some values from Cache entries to allocate another cache values. It indicates your Cache Size for that key is not enough. Will discuss more on this in a while.
- MaxSize — The approximate limit to the size of the cache. Comes from your Caching Configuration.
This can be better understood by opening the Cache Administration page on your local Sitecore instance. So, as per Sitecore Caching guide, below are the indicators that tell you to increase cache size:
- If the size of the cache is consistently more than 80% of the maximum cache size, increase the size of the cache by 25%.
- If the cache Delta fluctuates significantly, increase the size of the cache by 25%.
Lets try to understand this by example. A typical entry in cache.aspx for prefetch cache for master database looks like -
SqlDataProvider - Prefetch data(master) | 1042 | 191.8 MB | 43 bytes | 200 MB |
This entry on cache.aspx page tells us -
- Name Of Cache = SqlDataProvider – Prefetch data(master)
- Count (number of items in cache) = 1042
- Size = 191.8 MB
- Delta = 43 bytes
- Max Size = 200 MB
We can see Size of the cache is about to limit of 200 MB. 191.8/200 = 96% of max size.
This means that current cache size is not enough to handle all the data (96%>80%). The guide recommends to increase size by 25% i.e. to 250 MB
* If Delta goes to minus, this means that Sitecore wants to put fresh data into the cache, but it can’t because of limited cache size. So Sitecore deletes some data from cache and puts new data. Negative Delta value is an indicator to increase cache size.
How to know proper cache sizes?
- Run a load test using a tool (Gatling or JMeter) or by asking multiple users to use most important pages of your application simultaneously.
- If you are tuning caches for Content Delivery, use your load test to simulate visits to the published site.
- If you are tuning caches for Content Management, use your load test to simulate visits to the Experience Editor and Content Editor. Ideally, your test should include expanding the Content Tree.
- Open the Cache Administration Page of your Sitecore instance and keep refreshing it by clicking Refresh button. You shall see the number of items and cache size growing as the number of users increase.
- Identify some of the most important caches that need to be configured properly -
- While tuning the Content Delivery environment, pay particular attention to the following caches:
- web[data] (Data cache)
- web[item] (Item cache)
- SqlDataProvider- Prefetch data(web) (Prefetch cache)
- When tuning the Content Management environment, pay particular attention to the following caches :
- master[data] (Data cache)
- master[item] (Item cache)
- SqlDataProvider- Prefetch data(master) (Prefetch cache)
- If the Delta for a cache fluctuates constantly, or if the size of the cache is consistently above 80% of the size limit, then increase the size of the cache by at least 25%.
- If the size of the cache remains less than 50% of the MaxSize, decrease the size of the cache by 25%.
- Repeat the previous step until the caches are stable. A cache is considered stable when:
- The cache size is between 70% and 80%.
- The Delta value remains relatively consistent.
Your configuration patch shall look like -
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<databases>
<!-- Core DB -->
<database id="core">
<cacheSizes hint="setting">
<data>100MB</data>
<items>50MB</items>
<paths>1MB</paths>
<itempaths>20MB</itempaths>
<standardValues>1MB</standardValues>
</cacheSizes>
</database>
<!-- Master DB -->
<database id="master">
<cacheSizes hint="setting">
<data>1GB</data>
<items>500MB</items>
<paths>10MB</paths>
<itempaths>50MB</itempaths>
<standardValues>10MB</standardValues>
</cacheSizes>
</database>
<!-- Web DB -->
<database id="web">
<cacheSizes hint="setting">
<data>2GB</data>
<items>1GB</items>
<paths>10MB</paths>
<itempaths>50MB</itempaths>
<standardValues>10MB</standardValues>
</cacheSizes>
</database>
</databases>
</sitecore>
</configuration>
Few points to be noted :
- If you increase prefetch cache heavily, it may affect your Sitecore startup time. But, it will make application smoother after first start.
- Take care that large caches that consume all memory of the application can lead to out of memory exception. When the memory consumed by all application pools exceeds available memory on the system, Windows swaps memory to disk and can raise out-of-memory and other errors. Paging can adversely affect performance. Tune cache size limits to prevent paging and out-of-memory conditions.
Analyze requests on page load
Another step we took was to analyze the requests made by page during page load. This was done by -
- Open Developer tools in your browser (hit F12 in Chrome)
- Goto Network Tab (make sure to enable preserve log in Network tab to capture all the requests)
- Refresh the application page in the browser.
- Take note of all the requests that take time in seconds (not ms) to load (many requests will appear as pending requests)
Nice explained
ReplyDeleteThanks Vinodh!
Delete