PHP APC installation questions

While installing PHP APC, I received two unexpected questions. I had previously installed APC at a test environment and did not receive these questions.

The questions are:

  • Enable per request file info about files used from the APC cache
  • Enable spin locks (EXPERIMENTAL)

Here are the initial few lines of installation:

# pear install pecl/apc
WARNING: channel "pecl.php.net" has updated its protocols, use "channel-update pecl.php.net" to update
downloading APC-3.1.6.tgz ...
Starting to download APC-3.1.6.tgz (148,835 bytes)
..........................done: 148,835 bytes
49 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
 1. Enable per request file info about files used from the APC cache : no

1-1, 'all', 'abort', or Enter to continue: 
 1. Enable spin locks (EXPERIMENTAL) : no

1-1, 'all', 'abort', or Enter to continue: 
building in /var/tmp/pear-build-root/APC-3.1.6
running: /var/tmp/APC/configure --enable-apc-filehits=no --enable-apc-spinlocks=no

Does anyone know what these questions do? What would the proper answers be?


Solution 1:

The short answer is options can generally be left at the defaults, which you can take to be the "proper" answers.

The first option (--enable-apc-filehits) enables gathering information for the "filehits" option of apc_cache_info. Basically, you can use it to figure out which files are pulled from the cache for each request if you're debugging cache-related problems. From the apc_cache_info documentation:

If cache_type is "filehits", information about which files have been served from the bytecode cache for the current request will be returned. This feature must be enabled at compile time using --enable-filehits.

When it comes to the second option (--enable-apc-spinlocks), spinlocks are a processor-cycle inefficient way of ensuring only one process accesses a resource at any given time. APC uses locks when dealing with shared memory. APC places the cache in shared memory so that all the PHP processes can, well, share the cache, and locks ensure that the processes don't trip over each other while doing it.

As of APC 3.1.9, the PECL installer ask about enabling three additional options: memory protection, pthread read/write locks and pthread mutexes, which correspond to --enable-apc-memprotect, --enable-apc-pthreadrwlocks and --enable-apc-pthreadmutex. The first two are labeled experimental and disabled by default; the latter is enabled.

Memory protection treats some areas of shared memory as read-only in certain circumstances.

Pthread read/write locks and mutexes are alternate locking mechanisms. The locking mechanisms that APC can currently use are:

  1. file locking (fcntl)
  2. semaphores
  3. pthread locks
  4. pthread mutexes
  5. Slim reader/writer locks (Windows only)
  6. spinlocks

Stick to the default locking mechanism unless APC won't compile. Brian Shire at Facebook tested locking mechanism performance and presented the results back in 2007; you can use his results to guide you when trying locking mechanisms when the defaults fail.

Solution 2:

Instead of using AB for benchmarks, you should use siege wich is more accurate.