Friday, April 5, 2013

Improve Sitecore Media Library Performance with IIS ARR

Recently one of our Sitecore production environment was having performance issues. On troubleshooting we found that one of the causes was media library. It was performing poorly when there was heavy load on the server. Even after configuring various media library related settings in web.config, performance was not getting improved. We were still observing CPU spikes in production environment.

Due to budget constraints, CDN option was ruled out for media library. Then we came up with a solution to have a proxy before the CD server. We found that reverse proxy can be setup with help of IIS Application Request Routing and URL Rewrite.

After setting up reverse proxy, all media library requests were forwarded to CD server for the first time and its response was cached on disk. After creation of cache, media library request were not forwarded to CD server and instead were being served from cache.

When we performed load testing on our Staging environment, there was vast improvement in performance with ARR cache. CPU Utilization reduced by almost 10x times, Requests/Sec increased by 1.5x times and Response Time reduced to half.

Till now we haven't seen any functionality issues in Sitecore websites with ARR caches. All sites were working fine as expected.

One important setting to be configured in web.config file is to set HTTP Cache-Control Header to Public for media library files. This will enable media library items to get cached at proxy sites.
<setting name="MediaResponse.Cacheability" value="public" />

There are other ways as well to improve media library performance but more on that in later posts.