Thursday, October 25, 2007

The Object of My Cache

In the first post on caching I explained the output cache and how it can speed up your MOSS site. In this post I will explain the object cache. This cache comes ready to use in MOSS by default and does not require much tweaking except for the size of the cache.

Since MOSS uses SQL Server to store all the content of a site, it can get pretty expensive to make round trips to the database for each piece of content, so MOSS stores the most used objects such as document library and list fields and site navigation on the disk. This caching is very granular and is less expensive over time.

As the site administrator you can adjust the maximum disk size alloted for the object cache. The default is 100MB per site collection. In order to find the right size for this cache you will need to monitor the Sharepoint Publishing Cache in performance monitor. Keep an eye on the publishing cache hit ratio, and the total object discards counters to give you an idea of how you should adjust the cache size.

To change the size of the cache:

1. Click site actions->site settings->modify all site settings

2. Click Site Collection Object Cache

3. Change the value of Max. Cache Size and click OK.


One thing to keep in mind when using all of the different caches is that they all share the same virtual memory within the process. If you set the object cache really high that leaves less memory available for the other types of caching. If you are running on a 32-bit operating system then the W3WP process has a maximum limit of 2GB to use for the application. This 2GB also includes the space alloted to dll's and modules loaded by MOSS. A good rule of thumb for the object cache is to start at 200MB and increase it until the hit ratio is low high (< 85%). You can also test the cache by hitting the pages and seeing the response time for a user.

In the next post I will cover disk-based (BLOB) caching.

Labels: , , ,

Sunday, October 14, 2007

When a Cache is Not a Cache

The first problem area I had with our project was when we made the Internet-facing site live. We set up output caching and BLOB caching to cache pretty much all of the site. We also setup the Object cache. We figured we had our bases covered because we tried these things on our development site and they increased page load time significantly.

The site went live and it was doing well for most of the morning when 11 o'clock hit and we now had 3 time zones worth of people hitting the site. We suddenly noticed that the processor was getting pegged at 100% and that the amount of memory used was increasing quite quickly.

After spending a week looking at the performance monitor for various counters and checking Microsoft documentation, we had finally figured out that some of the memory leak was due to not cleaning up SPRequest objects. We cleaned up all of our custom code and this improved the site marginally. We also began tweaking the output cache to find a good balance and settled on 4 hours for pages to be cached. The BLOB cache works wonderfully, it caches images, and other Binary Large Objects. It is awesome to see whole pages load without images filtering in one at a time.

The site was still not running quite right and we had noticed on the object cache counter that objects were being thrown out of the cache as soon as they were put in. I began monitoring the SharePoint logs and found that pages were being invalidated and thrown out of the cache. So this led to a call to Microsoft. After the same questions and sending them an SPSReports CAB file, they came back saying that the object cache does not cache custom code objects. This didn't fare well as almost every page of our site has custom code on it. After looking over the options and Microsoft telling me that there was no expected date for a fix, we decided to monitor the site some more and noticed that the page output was still being cached, so the object caching not storing our code was only going to be a problem for the first person to hit that page. We decided that this was acceptable performance for the site.

In the next few blog posts I will explain the various types of caching and how they can help your MOSS site's performance and scalability (especially if an Internet-facing site).

Labels: , , , , , , ,