Friday, April 02, 2010

Sitecore Installation Wizard – disable search index update during install


OK, now after my April Fools joke, let’s talk about serious things around Sitecore .NET CMS. Such as how to speed up installation of Sitecore packages.
One of the things that improve the performance of the package installation is disabling the search index update temporarily via the following setting:

<setting name="Indexing.UpdateInterval" value="00:00:00" />

Setting this interval to all zeros actively disables the background index update job that maintains Sitecore’s search index.

While you can certainly do this manually, it is not always feasible since you need to edit web.config (have access to the server, etc) plus it restarts the application.

What you can do however is to add some logic to the Installation Wizard, specifically a flag to temporarily disable the search index updates during the package installation:
clip_image002

To make this happen, do the following:

1. Create the following class in your project and compile it.

namespace SCUSAINC.Custom.Packager
{
   using System;
   using Sitecore.Reflection;
   using Sitecore.Web.UI.HtmlControls;
   using Sitecore.Web.UI.Sheer;
   using Sitecore.Shell.Applications.Install.Dialogs.InstallPackage;

   public class CustomInstallPackageForm : InstallPackageForm
   {
      [HandleMessage("installer:setTaskId")]
      private void OnSetTaskId(Message message)
      {
         var obj = this as InstallPackageForm;
         ReflectionUtil.CallMethod(typeof(InstallPackageForm), obj, "SetTaskID", true, true, new object[] { message });
      }

      [HandleMessage("installer:commitingFiles")]
      private void OnCommittingFiles(Message message)
      {
         var obj = this as InstallPackageForm;
         ReflectionUtil.CallMethod(typeof(InstallPackageForm), obj, "OnCommittingFiles", true, true, new object[] { message });
      }

      protected Checkbox DisableIndexing;

      protected override void OnLoad(EventArgs e)
      {
         DisableIndexing.Checked = false;
         base.OnLoad(e);
      }

      protected override void OnNext(object sender, EventArgs formEventArgs)
      {
         base.OnNext(sender, formEventArgs);
         if (Active == "Installing" && DisableIndexing.Checked)
         {
            Sitecore.Configuration.Settings.Indexing.Enabled = false;
         }
      }

      protected override void EndWizard()
      {
         base.EndWizard();
         if (DisableIndexing.Checked)
         {
            DisableIndexing.Checked = false;
            Sitecore.Configuration.Settings.Indexing.Enabled = true;
         }
      }
   }
}

2. Copy the following file to the /sitecore/shell/override folder: \sitecore\shell\Applications\Install\Dialogs\Install package\Install Package.xml

3. Open this XML file

4. Change the CodeBeside reference in the XML source file to your custom name:

<WizardForm Application="Tools/Installer/InstallationWizard" CodeBeside="SCUSAINC.Custom.Packager.CustomInstallPackageForm,SCUSAINC.Custom ">

5. Add the checkbox definition to the XML source:

<WizardFormPage ID="Ready" Header="Ready to Install" Text="The wizard is ready to install the package. Click Install to install the package." Icon="People/32x32/Box_Software.png">
   <WizardFormIndent>
     <GridPanel Columns="2" CellPadding="2" Width="100%"></GridPanel>
     <Checkbox ID="DisableIndexing" Header="Disable search index update during the install" Checked="True" />
   </WizardFormIndent>
</WizardFormPage>

Based on my tests, this significantly decreases the installation time (up to a half), especially on high volume packages in terms of content items.

Special thanks to Paul from Sitecore Support and Sergey from the development team for the assistance with this!

4 comments:

David said...

Alex, this is great! Exactly what I was looking for. What's the behavior of Lucene when you enabled indexing?

Lets say I update 400 content items, will Lucene take hold of significant processing power to catch up in reindexing?

Also, when would it know to start catching up? As soon as we hit the code to enable Lucene indexing?

Alex Shyba said...

David,

400 items is substantial, but not that much in my personal experience. You will definitely see CPU spiking up, but the actual effective impact of this depends mainly on the number of fields each item carry and hardware.

As soon as the installer finishes up, the indexing will be enabled back and the entries will be processed when alarm clock rings on scheduled interval defined within the Indexing.UpdateInterval setting.

If it is a large package, I'd recommend running full index rebuild from the control panel after the install.

This will take care of all the "old" indexes that are bound to the databases, and also "new" default "system" index. If you have custom "new" indexes, you will need to rebuild them programmatically.

it.mrunal@gmail.com said...

Very useful....

Kevin Obee said...

Alex, great post. I've applied your solution to my Sitecore.Ship project so that I can suspend updates to the search indexes whilst packages are being installed.

Does this approach still work with the changes to search that were introduced by Sitecore 7? If not can you suggest how I might achieve the same effect in Sitecore 7.