Measuring the Output Cache on SharePoint 2010

Output cache is a very interesting featuere on IIS, ASP.NET and also on SharePoint 2010. It helps a lot to reduce the processing time of the requests on the server and improves the number of requests your servers can serve.

Last week I wrote an article about output cache configuration, now it is time to talk about how to check if the cache is working and how it is behaving.

The out of the box Windows Performance Monitor is a tool we can use to monitor the output cache. This monitoring needs to be done on all web front end (WFE) servers because each WFE server will have its own instances of the output cache. Each web application will have one instance of the output cache.
To launch the Performance Monitor, go to the Administrative Tools menu and click on Performance Monitor. Once the tool is loaded it will display the performance counter for total CPU time by default.

Click on the green cross to selected which performance counters to add.

Go to the ASP.NET Applications category, select the counter you need and choose the IIS site for the web application you will monitor.

The output cache counters are:

Output cache entries: current number of items on the cache. It will increase every time a new page is requested and the cache doesn’t have a copy of it, so the page will get processed and cached.

Output cache hit ratio: the percentage of hits served by the cache instead of having IIS and SharePoint to process the page.

Output cache hits: number of hits server by the cache instead of having IIS and SharePoint to process the page.

Output cache misses: number of hits processed by IIS and SharePoint.

Output cache trims:

Output cache turnover rate: number of additions and removals from the cache per second. Indicates how the cache is being used and if it is effective. If it has a high turnover the cache is not being used.


It is a good idea to adjust the scale for the performance counters. They will be added to the UI in a 0.1 scale. Change it to 1.0 in order to have a better view of the variation for the values.

After you have all the counters configured you can starting testing hitting parts of the site and see how the output will behave and also the response on the browser. For the first time you request a page it should take longer to return to the browser and on the monitoring you should see a new item being added to the cache. On the next requests for the same page, it should load faster and the number of cache hits and the hits ratio should be increased.

In order to run a monitoring session and save the data you need to Data Collector Set. This is a good article on how to do it:

Create a Data Collector Set to Monitor Performance Counters

See you,

Amadeu.

SharePoint 2010 Cache Configuration

Cache is a very important feature when you think about end user response time and also server load. In my case, I was tweaking the configuration for a internet public sites in order the have a better user experience.

BLOB Cache

To improve the end user response time a good approach is to configure the BLOB Cache on the SharePoint 2010 Web Front End (WFE) servers. The BLOB cache caches files on the WFEs disk to make it faster for IIS to retrieve the files and return them to the browser. It can also send some HTTP headers telling the browser to cache the file for a certain amount of time.

We need to change the web.config to enable the BLOB cache. Find the BlobCache tag on the configuration/SharePoint node on the web.config. Here is an example of a configured Blob Cache:

<BlobCache location=”C:\BlobCache\14″ path=”\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv)$” maxSize=”10″ enabled=”true” max-age=”36000″ />

The location attribute defines where SharePoint is going to save the cached files.

The path attribute represents a regex defining the file extensions to be cached.

The maxSize attribute defines the maximum size of the cache in Giga bytes.

The enabled attribute defines if the cache is enabled.

The max-age attribute defines the maximum time in seconds the browsers can cache the files locally and avoid making requests for these file to the server. This setting affect how the users’ browser cache the files defined on the path attribute.

Output Cache

Another cache feature available on SharePoint 2010 is the Output Cache.

The Output Cache caches the HTML output for the pages processed by SharePoint. This cache improves the server processing time for the cache pages since IIS doesn’t need to call SharePoint and wait for the page to be processed. It just gets the cached copy and send the HTML back to the browser. The Output Cache is configured per Site Collection.

First we need to make sure the cache profile is configured in the way we need.

Go to the Site Settings page, then to Site Collection Administration and then to Site Collection Cache Profiles.

The default cache profiles are listed. I’ll check if the Public Internet one is alright for my needs.

In my case I’ll need a few tweaks on the cache profile configuration:

  • Check for changes: This setting needs to be Yes in order for the cache to items in the cache if they changed before the duration of the cache. It affects performance but it is a good option to make sure Content Managers have their content showing up on the site as soon as they approve it.
  • Vary by query string parameters: Since we have several dynamic pages which receive parameters by query string and produce different HTML in the output we need to specify the query string parameter. The value of the parameter should be * since the names of the parameters vary a lot.

My new cache profile looks like this:

After your cache profile is ready, you should go to the Site Settings page, then to Site Collection Administration and then to Site Collection Output Cache.

Make sure you enable the Output Cache and select the cache profile you just created.

Testing

Now you just need to recycle your app pools and start testing the cache. Both caches can be tested in HTTP monitoring tools such as FiddlerHTTP Watch, IE Developer Tools or Chrome Developer Tools.

Two important notes on testing:

  • If you hit F5 on a page, your browser will sent HTTP headers to the server telling it to ignore any cache. The best way to test is navigating thru the site and checking which page and assets (images, js, css files) are called or cached.
  • If you configure your browser to always request the most current version of the page, the BLOB cache will not work on the client side.

References

More references about caching can be found at:

SharePoint BlobCache Explained
Digging Deeper into the 2010 Caching Options: Part 1
Digging Deeper into the 2010 Caching Options: Part 2
Client-Server Interactions and the max-age Attribute with SharePoint BLOB Caching
BLOB Cache, HTTP 304 Results and F5/Refresh

See you,

Amadeu.