Large EventQueue causes timeouts and restarts


Symptoms

High CPU usage, high memory use, or repeated restarts can occur when the EventQueue table in the Master or Web database grows considerably. Cleanup of the queue can then fail with timeout errors, and on Azure App Service the Event Queue Statistics page can time out before the cleanup finishes. The issue can be more likely when the rate of item changes is high or when average event entries are large.

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Actions

To mitigate the issue and reduce future EventQueue growth, perform the following:

  1. If the Event Queue Statistics cleanup page does not complete, run the following query directly against the affected EventQueue table in the Master or Web database.
    TRUNCATE TABLE [EventQueue]
  2. Rebuild the search indexes specific to the affected database.
  3. Create a backup of the configuration files before making changes.
  4. Create a configuration patch file in \App_Config\Include\zzz to set a stable InstanceName and run CleanupEventQueue more frequently. The following example keeps only recent events and runs the cleanup every hour.
    <?xml version="1.0" encoding="utf-8"?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
    <sitecore>
    <settings>
    <setting name="InstanceName" value="CM" role:require="ContentManagement" />
    </settings>
    <scheduling>
    <agent type="Sitecore.Tasks.CleanupEventQueue, Sitecore.Kernel" set:interval="01:00:00" role:require="ContentManagement">
    <DaysToKeep>
    <patch:delete />
    </DaysToKeep>
    <IntervalToKeep>04:00:00</IntervalToKeep>
    </agent>
    </scheduling>
    </sitecore>
    </configuration>
  5. To help prevent recurrence, avoid saving large text values of about 1 MB in Sitecore item fields.

Note: If a large queue was cleared directly in the database, rebuilding the search indexes for the affected database is recommended.