Never Underestimate The Power of Defrag

Monday, 8 December 2008 21:34 by RanjanBanerji

Very often I hear people make comments like "I have no idea but my servers are running really slow."  A common cause for this magical slow performance is a highly fragmented drive.  High levels of fragmentation will result in excessive disk I/O which will impact the performance of your servers.

A few years ago we were experiencing very slow query responses from an Oracle server.  The DBA laughed at me when I said check the drives.  Eventually when we checked sure enough the drives were extremely fragmented.  Once defragged (if I may use the term) the problems vanished.

Today I happened to be diagnosing why one of our servers running SharePoint and SQL Server was behaving so poorly.  A simple select count(*) from AuditData was taking over 2 minutes to return data.  Granted that the table had 13 million records. I wrote a script to delete records from this table using the SharePoint API and the code just sat there chugging for 4 hours at the end of which I had to terminate it.  A casual glance showed that this appeared to be a problem triggered by poor I/O.  When I checked the drives this is what I found.

defrag

 

That much red is just not good.  So before you get down to lengthy discussions about query optimizations and table indexes please stop and make sure your server is not screaming for help.

 

 

Categories:   IT
Actions:   E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

SharePoint Harvester

Thursday, 13 November 2008 23:27 by RanjanBanerji

Often one has to write code to loop through all of SharePoint to make some sort of a sweeping change. Making such changes directly in the database is a bad idea and is not supported by Microsoft. So the best way to do so is to use the SharePoint WSS object model. SharePoint Harvester hopefully will make it easier to do so by providing a recursive traversal of a SharePoint application firing events when a site, list, item etc is found.

The SharePoint harvester code is really simple and can be accessed from http://www.codeplex.com/SharePointHarvester.  I am not going to start discussing the code itself.  Simple recursion and when webs, lists, items, etc are found it calls a virtual method and fires an event.  This way a user may choose to inherit from this class and override some methods or they can subscribe to relevant events.

So for example if you want to turn off versioning for every list in on every site in an application.  How would you do that?  You could go through the UI and browse to each site and each list and then turn off versioning for that list.  What if you had 500 sites each with 10 lists.  That is a lot of work.  Using SharePointHarvester you could do something like:

public void TurnOffVersioning() {
    SiteHarvester siteHarvester = new SiteHarvester();

    siteHarvester.Url = "http://some.sharepoint.url";
    siteHarvester.Recursive = true;

    siteHarvester.ListFound += new ListFoundHandler( siteHarvestor_ListFound );
    siteHarvester.RunHarvester();

}

void siteHarvestor_ListFound( object sender, ListFoundEventArg e ) {
    e._list.EnableVersioning = false;
    e._list.Update();
}

You do not have to run this code for the entire application.  The URL you provide could easily have been for some sub site, for example:

siteHarvester.Url = "http://some.sharepoint.url/SomeSite/SomeSubSite";

Harvester will now only get lists for SomeSubSite and all its descendant sites.  As you can see, it makes life a lot easier instead of having to write the recursive code over and over.  More complex situations can now be handled.  For example what if you wanted to check-in all images that have been checked out across the entire application, or delete versions of all images because you are suffering from DB bloat.

More examples will follow.