JasonDaly.name

PHP, Ruby, Symfony, Rails, Doctrine, MooTools. Web Development.
July 9, 2010

Symfony Functional Tests + PHP APC Cache Slam Warning

After implementing query caching using Doctrine’s Doctrine_Cache_Apc interface in a Symfony application I am working on, when running the application’s functional tests, warnings were returned intermittently in a few places

$ [apc-warning] Potential cache slam averted for key ...

In APC >= 3.0, an apc.slam_defense configuration option was added in attempt to avoid repeated writes to the same APC cache key as might occur under very high traffic. This apc.slam_defense option was later removed due to having been deprecated in favor of apc.write_lock as of APC >= 3.0.11. This is enabled by default, so the first thing I tried in my development environment was disabling this option. A simple test case will still fail though with apc.write_lock disabled.

apc_store('my_key', 1);
apc_store('my_key', 2);

echo apc_fetch('my_key'); // outputs 1, not 2

One of the more recent comments in this PECL ticket for APC offers a patch that can be applied to the latest release of APC before compiling it. This patch re-introduces the previously removed apc.slam_defense option. For my development environment only (since the cache slam warnings thrown in this environment due to my functional tests are irrelevant), I fixed the cache slam warnings by following these steps

  1. Download a fresh copy of the latest release of APC (3.1.3p1)
  2. Apply this patch
  3. Build and install APC
  4. In php.ini, add the newly recognized apc.slam_defense=0

With apc.slam_defense in place and disabled, the test case above and my application’s functional tests run without any cache slam warnings.

2 notes Tags: php symfony code apc cache caching doctrine doctrine_cache

  1. d4ly posted this