Tag1 Consulting

Performance and Scalability Experts

Page-cache Lock

Description:
This patch is designed to prevent cache stampedes when updating pages in the Drupal page cache. When serving cached pages, logic checks the timestamp of the cached page -- if older than the global timestamp we try to grab a lock. Only one user can grab the lock for a given page at a time. If the user fails to grab the lock, a stale version of the cached page is returned. Once the page is rebuilt, the new version is returned on subsequent requests.

If using this patch, it is highly recommended that you also apply the page-cache-memcache lock patch. Attempting to use this patch in production without memcache will inevitably result in many stale locks as this patch currently does not provide any garbage collection. This patch is intended to be used together with the external page-cache patch.

Here's an ASCII art explanation of the patch:

    Timer  Action   
    0ms:
     |----> Page request #1, obtain lock, rebuild page
    1ms:
     |----> Page request #2, failed to obtain lock, serve page from cache
     |                      
     |----> Page request #n, failed to obtain lock, serve page from cache
     |                      
    250ms:
     |      Page request #1 finished building new page cache, page cache updated
     |----> Page request #n+1, up-to-date, nothing to rebuild, serve from cache

This patch has been updated to use the new locking framework included in Drupal 6.17. The cache_lock table is no longer required for this patch.

Status:
This patch has not been merged into any release of Drupal.

Patch:
http://tag1consulting.com/patches#lock

Original patch source:
http://drupal.org/node/230290
http://drupal.org/files/issues/pagecache_lock3.patch

Referenced external pagecache:
http://tag1consulting.com/patches/external_pagecache