1
  1. I am using Sitecore 9.1 and I need to know what things I should keep in mind before performing bulk operation programmatically on Sitecore Items for multiple languages in parallel to avoid the SQL deadlock issue?

  2. I am using the below code to update the product item. Please let me know if this is correct or should I use using(new BulkUpdateContext())?

using (new EventDisabler())

using (new SecurityDisabler())
{

  productItem.Editing.BeginEdit();

   //code to update productItem fields

  productItem.Editing.EndEdit();

}

2 Answers 2

0

A few scenarios can happen during bulk operation that causes deadlocks are:

  1. Events, history, and publishing tables Sitecore uses these tables to keep track of events, history, and publishing. If these tables consist of hundreds of thousands of records then they will fail to retrieve the info in a timely fashion and thus slowing the CPU and memory and thus resulting in deadlocks.
  2. You have to prune the data in these 3 tables. You can also create a job that regularly cleans up data from these 3 tables, archives it in another table, and later cleans the archive table to say on weekly basis.
  3. Never use Sitecore Fast query for Item Bucketing search If you are using the fast query for getting the bucketing item or any other operations to get the data. It should fetch data using the index to avoid deadlocks. We were searching events from around 5000 bucketing items, and due to a high concurrent load(1000 requests) it occurred the deadlock situation, then we changed the query(Index Content Search) to get the item bucketing items as per the Sitecore recommendation.
  4. Link Database SQL Server transaction deadlocks related to the link database could occur when multiple threads were creating and moving items concurrently, You can Disable updating the link database on publish. <setting name="LinkDatabase.UpdateDuringPublish" value="false"/>

Yes, your code sample will work for updating product items. You can update code like.

using (new Sitecore.SecurityModel.SecurityDisabler())
{
 {
    productItem.Editing.BeginEdit();

    try
    {
      productItem.Fields["Title"].Value = "Value1";
      productItem.Editing.EndEdit();
    }
    catch (System.Exception ex)
    {
       productItem.Editing.CancelEdit();
    }
 }
}

Refer to this for more details. Create items in Sitecore

Hope it helps!

0

I would suggest the following things to avoid deadlock.

  1. Check the EventQueue size

Deadlocks occur if your EventQueue is too large. Make sure you clean the EventQueue often and keep as little data as possible, preferably below 1000 items. The CleanupEventQueue task will help you:

  1. Let your CM server do the publishing

Most of the EventQueue contents is publish information. If possible, your architecture should allow on the CM server to publish. The CD servers should not.

  1. Have enough power in the server rack

Deadlocks occur more often on heavily loaded environments, because the insert and select statements will be slower. Make sure you do not constantly run out of CPU or memory on your web and SQL servers.

To bulk update you can use the following code.

using (new SecurityDisabler())
using (new ProxyDisabler())
using (new DatabaseCacheDisabler())
using (new EventDisabler())
using (new BulkUpdateContext())
{
    try
    {
        Sitecore.Configuration.Settings.Indexing.Enabled = false;

            for (int i = start; i <= end; i++)
            {
            // update / insert / add / delete items here
            }
        }
    finally
    {
        Sitecore.Configuration.Settings.Indexing.Enabled = true;
    }
}

Refer to this one: https://horizontal.blog/2016/02/12/disablers-disablers-disablers-disablers-a-lesson-in-mass-sitecore-updates/

So add the 4 disablers, the bulk update context and the disabling of indexing will speed up the bulk update process.

Another way you can use is with Powershell Script. Use the following code for bulk update.

New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
foreach ( $item in (Get-ChildItem -Path master:\Content\Home -Recurse -WithParent) ) {
        $item."MetaTitle" = $item.Title
    }
}

Refer to this for whole implementation.

https://www.bartlomiejmucha.com/en/blog/how-to-populate-sitecore-with-test-data-using-power-shell

2
  • Thank you so much for all your suggestions. Would like to know - can we use productItem.Editing.EndEdit() or productItem.Editing.EndEdit(true) within using (new EventDisabler())? Apr 7, 2023 at 11:42
  • You should write your code where it is mentioned //Update/insert/add/delete items here section. Apr 7, 2023 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.