You can generate near-100% miss rates on certain caches in 1.9 if the entity being cached uses CACHE_TEMPORARY. This means that there is a > 2:1 WRITE TO READ ratio.

Here's the problem:

Notice that in the code below, $expire is not (re-)set until after its value is assigned to $cache->expire.

This seems to result in the behavior that every CACHE_TEMPORARY item expires every time. (See dmemcache_get() for fetching code -- -1 is definitely less than time()).

Furthermore, $expire is never set to the actual expiration time. It is just the number of seconds to wait. The expire time should be variable_get('cache_lifetime', 2591999) + $time

function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL) {
  $time = time();

  // Create new cache object.
  $cache = new stdClass;
  $cache->cid = $cid;
  $cache->data = is_object($data) ? memcache_clone($data) : $data;
  $cache->created = $time;
  $cache->expire = $expire;
  $cache->headers = $headers;

  // Save to memcache
  if ($expire == CACHE_TEMPORARY) {
    $expire = variable_get('cache_lifetime', 2591999);
  }
  // We manually track the expire time in $cache->expire.  When the object
  // expires, we only allow one request to rebuild it to avoid cache stampedes.
  // Other requests for the expired object while it is still being rebuilt get
  // the expired object.
  dmemcache_set($cid, $cache, 0, $table);
}

I believe this bug should be marked critical, given the fact that it actually hurts overall system performance, rather than helping.

CommentFileSizeAuthor
#1 memcache-5x-19-20100114.patch901 bytesmbutcher

Comments

mbutcher’s picture

StatusFileSize
new901 bytes

Patch attached.

mbutcher’s picture

Status: Active » Needs review

D'oh... sorry... should have marked this as "Needs Review"

robertdouglass’s picture

Will

bendodd’s picture

I have been looking at, what seems to be a similar issue (although mostly with cache clearing and D6):
http://drupal.org/node/572838#comment-2690370

catch’s picture

Status: Needs review » Closed (won't fix)

Just marked 5.x as unsupported, won't fixing this.