I've been meaning to post about this for some time now, so I decided there is no time like the present. All of the tips below apply to both MOSS 2007 and SharePoint 2010.
When you are setting up a SharePoint site, performance is often an overlooked item. It is particularly important for public web sites, but Intranet sites an collaborative sites benefit from this as well. We'll use our own Envision IT public web site (www.envisionit.com) as the example. The items that we'll cover are:
- Setting up the site collection object cache to improve the content query web part performance. These web parts are used extensively in the sites
- Enabling and configuring the cache profiles (which are off by default)
- Turning on the disk-based BLOB cache for binary objects (images, PDFs, etc.)
- Setting up a wake-up script to run nightly to hit the sites and cause the caches to get initialized and populated, as well as ASP.NET started up
Site Collection Object Cache
The site collection object cache is used by the content query web parts to cache their results. It is accessed by going to the Site Settings of the top-level site, and selecting Site collection object cache from the Site Collection Administration section.
- The default object cache of 100 MB was used
- The cross list query cache was turned on with a cache time of 300 seconds
- It does mean you may see up to a five minute lag for changes to show up on the public site, but it significantly increases the performance of the content query web parts, which are used extensively on most publishing sites
- The default cross list query multiplier of 3 was used. This is used to broaden the scope of a query so that future queries may get all their results from cache rather than having to go back to the database
Cache profiles are used to define the caching behaviour for different user profiles. By default caching is turned off. The following profiles are defined, but additional profiles can be created.
- Public Internet (Purely Anonymous)
- Extranet (Published Site)
- Intranet (Collaboration Site)
The main differences between the profiles are how they behave for content authors. For public access, authoring is generally not permitted, so the goal is to maximize the performance without ensuring a full fidelity editing experience. For our site, we used the Public Internet profile for anonymous access, and the Intranet profile for authenticated (which would be our content authors).
Cache profiles are configured from the Site collection cache profiles option in the Site Settings of the top-level site. Cache settings are selected from the Site collection output cache option.
BLOB Disk Cache
In order to improve the performance of serving up binary objects, the following line was added to the web.config for the web app. This causes all binary files that match one of the listed extensions to be cached for a period of 24 hours on the disk of the server. The maxSize parameter is maximum size in Gb for the 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" />
Each night ASP.NET tends to recycle the app pool in IIS. This causes the next load of the site to be quite slow, as ASP.NET precompiles all of the elements, and items get loaded into the caches.
To improve the first visitor experience each morning, it is recommended to have a wakeup script run each night to take the hit for this. This is done using SPWakeUp.exe, which is a Code-Plex component used to wake up SharePoint sites. More details and full open-source code can be found at http://www.codeplex.com/SPWakeUp. Basically it exercises each site and site collection in a SharePoint server to rebuild its IIS cache. The current version has been completely updated to work with SharePoint 2010.
On our site SPWakeUp is scheduled using Windows Scheduler to run at 4 AM every day. We don't provide any arguments, which means it wakes up all the sites on the server. If you have multiple front-end servers, you do need to schedule it on each server. We typically load the executable in the C:\Program Files\SPWakeup folder. No additional files are required.
By adding the wakeup script to our server, we took our time to display the first page content after an IISReset from 27 seconds to 650 ms. Quite an improvement to the user experience.