Cloud Platform

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.

Important

If you want to use Memcached to store your semaphore locking mechanism, and are both willing to assume the risk and have tested the effects on your application, the Memcache API and Integration module provides the features and instructions necessary to store Drupal’s semaphore table in Memcached.

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:

Important
  • Enabling stampede protection without moving locks into Memcached can cause a severe performance degradation if Memcached locks, and then waits to retry. You can use Memcache for lock management without enabling stampede protection.
  • Enabling stampede protection and lock management in Memcache might cause downtime in environments running on Cloud Next technologies. For more information, see Disabling stampede protection and lock management in Memcache.

Enabling stampede protection and lock management in Memcache

Important

Before enabling stampede protection and lock management, you must first have the Memcache API and Integration module installed and configured. For more information, see Enabling Memcached on Cloud Platform.

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';