Doug on SharePoint

Stuff on SharePoint and other things.

Moss Object Caching

First I wanted to thank Sean McDonough for his blog post MOSS Object Cache Memory Tuning is not an Intuitive Process it assisted a great deal with a stability problem we were having with a publishing portal.

So here was the problem: The company has an internal portal (yes it is on a 32 Bit machine) that is getting around 65-70K unique visitors per day. It wasn’t until the last couple of weeks that the traffic was that high, but due to a DNS change the old portal is now pointing to the new SharePoint Site. Soon after the change, the site just was not stable at all. We were seeing a lot of app pool resets, slow response, and a lot of out of memory errors.

After doing some searching we found that the Object cache settings was set to 1GB (the default is 100MB)! You can read about SharePoint caching here on TechNet. The thing is, the object cache sits in the worker process and on a 32 Bit system there is only the 2GB application memory space. With the added pressure on the application memory it just could not handle it.

Using Sean’s blog and his recommendation of looking at the SharePoint Publishing Cache/Total number of cache compactions, we reduced the cache to 300MB (it was set at 500MB as an arbitrary number that the application team would agree to) watched it for a day and we saw an increase in the compactions to 2-3, at 500 the counter was at 0. We then increased the memory to 350MB and watched it for a day and continued until the optimal setting was found for the Object Cache.

Imagine what would happen if you has a single web application for publishing sites? Every site collection admin could change this setting. Now just because the setting is at something like 500MB doesn’t mean that they will automatically reserve that amount of memory, it just means that if needed the cache will grow to that amount but on a 32 bit machine it would have a great impact on all of the sites in the web app. This got me thinking, how can I control this? I could not find a global setting in the central admin nor could I find an STSADM command (out of the box) to run. PowerShell!

I created a PowerShell script that I could use to loop thru the site collections on a web app and set the cache back to the default (or whatever you want it to be). Here is what I did.

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint.Publishing”)

$site = new-object Microsoft.sharepoint.spsite(“http://mosssite”)

$webapp = $site.Webapplication

foreach ($sites in $webapp.sites){

$cacheSettings = new-object Microsoft.SharePoint.Publishing.SiteCacheSettingsWriter($sites.url);

if ($cacheSettings.objectcachesize -gt 100){

$cacheSettings.ObjectCacheSize = 100;

$cacheSettings.Update();

$sites.url;

}

}

Note: dont forget to dispose!

09/18/2009 Posted by | Administration, Powershell, SharePoint | , | 1 Comment