If you are using memcache, and I'm sure other types of alternative cache backends, there is an option for "stampede protection", which tries to ensure that several requests don't try to rebuild the same cache simultaneously, which may be an expensive operation for the system.

Metatag has an option to enabling caching, however it still attempts to read from the cache even when the setting for caching is disabled. This most prominently happens in metatag_page_build():

if ($cache = metatag_cache_get($cid)) {
      $metatags = $cache->data;
    }
    else {
      $metatags = metatag_metatags_view($instance, array());
      // If output caching is enabled, save this for later.
      if (variable_get('metatag_cache_output', FALSE)) {
        metatag_cache_set($cid, $metatags);
      }
    }

The problem is that with stampede protection on, the call to metatag_cache_get() will get a cache miss and then lock_wait for that cache item until the lock is released. Locks are released when the cache finally gets set, but since the cache setting is off, this doesn't happen.

In my particular case, we had enabled the setting for metatag caching, and then later disabled it. I think that could be the root cause of this whole thing - if the cache setting is never enabled in the first place, this may not be a problem, I'm not sure.

Here's a screenshot from New Relic of what the trace looks like when waiting:
https://imgur.com/a/9KVeccJ

CommentFileSizeAuthor
#2 metatag-n2966185-2.patch922 bytesdamienmckenna

Comments

justindodge created an issue. See original summary.

damienmckenna’s picture

Version: 7.x-1.25 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new922 bytes

Does this help?

justindodge’s picture

@DamienMcKenna - yes, that is perfect. This is exactly the fix I applied in our own use case. I intended to contribute a patch, but time got the better of me.

The patch I applied to our production environment is not verbatim duplicate of this, but it's functionally identical and it has resolved the issue for us.

justindodge’s picture

Status: Needs review » Reviewed & tested by the community

damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed
Parent issue: » #2958474: Plan for Metatag 7.x-1.26

Committed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.