Loading...

Enabling stampede protection and moving locks into memory

Excessive database load may overwhelm the Drupal’s semaphore table, which can cause deadlocks. Encountering deadlocks during database write operations (including INSERT, UPDATE, and DELETE operations) can indicate that Drupal’s lock API is in conflict with InnoDB’s row-level locking mechanism on Drupal’s semaphore table.

Acquia recommends you keep the semaphore locking mechanism in your InnoDB database, due to your InnoDB database being a persistent storage location. Due to semaphore locks being intended for persistent storage, Memcached (as non-persistent storage) isn’t an ideal location for this use case.

Stampede protection

You can also use Memcached to provide stampede protection. In certain situations, using Memcached can help reduce the risk of performance degradation when several requests simultaneously try to write to the cache.

Stampede protection uses Drupal’s locking layer to allow only one process at a time to try to send an item to Memcached. However, MySQL’s InnoDB storage engine isn’t well-suited to managing locks in the semaphore table when experiencing high loads. Due to this behavior, it’s important to also move lock management out of the database and into memory if you enable stampede protection.

Acquia strongly recommends that you review the Memcache module’s README.txt file for complete documentation about its configuration:

Enabling stampede protection and lock management in Memcache

For instructions about how to enable stampede protection and Memcache lock management in your Drupal application, select the tab that indicates your installed version of Drupal:

Complete the following steps:

  1. Download and add the memcache.yml file to your website’s docroot/sites/[site_folder] directory.
    For a single site configuration, the directory is docroot/sites/default.
  2. Add the following lines at the end of the relevant file to enable stampede protection, remembering to replace [site_folder] with your site directory name:

    For Cloud Platform :  docroot/sites/[site_folder]/settings.php file

    For Site Factory : factory-hooks/post-settings-php/acsfd8.memcache.settings.php file

    // Enable stampede protection.
    $settings['memcache']['stampede_protection'] = TRUE;
    
    // Move locks to memcache
    $settings['container_yamls'][] = 'sites/[site_folder]/memcache.yml';

Disabling stampede protection and lock management in Memcache

To disable stampede protection and lock management in Memcache:

  1. Remove any memcache.yml file from the website's directories, docroot/sites/[site_folder].
  2. To disable stampede protection, remove the following lines from your settings.php file. Note that the code lines might not appear next to each other in your file.

    // Enable stampede protection.
    $settings['memcache']['stampede_protection'] = TRUE;
    
    // Move locks to memcache
    $settings['container_yamls'][] = 'sites/[site_folder]/memcache.yml';

Did not find what you were looking for?

If this content did not answer your questions, try searching or contacting our support team for further assistance.

Back to Section navigation