PoolCounter

To avoid massive wastage of CPU due to parallel parsing when the cache of a popular article is invalidated (the "Michael Jackson problem"), we now have a pool counter which limits the number of processes that may work on a given parse operation at any given time.

Source

 * The client source is in /trunk/extensions/PoolCounter
 * The server source is in /trunk/extensions/PoolCounter/daemon.
 * The server can be installed via APT, with the poolcounter package. The source in Subversion is in Debian-native form, so recompilation is just svn export && dpkg-buildpackage.

Architecture
The server is a single-threaded C program based on libevent. It does not use autoconf, it just has a makefile which is suitable for a normal Linux environment.

The server currently has no daemonize code, and so is backgrounded by start-stop-daemon -b.

The network protocol is line-based, with parameters separated by spaces. The following commands are defined:


 * ACQ4ANY: This is used to acquire a lock when the client is capable of using the cache entry generated by another process. If the pool worker limit is exceeded, the server will give a delayed response to this command. When a client completes its work, all processes which are waiting with ACQ4ANY will immediately be woken so that they can read the new cache entry.


 * ACQ4ME: This is used to acquire a lock when cache sharing is not possible or not applicable, for example when a stub threshold is set. When a lock of this kind is released, only one waiting process will be woken, so as to keep the worker population the same.


 * RELEASE: releases a lock

Configuration
The server does not require configuration. Configuration of pool sizes, wait timeouts, etc. is done dynamically by the client. The server currently runs on tarin. Installation of the poolcounter package is done via puppet.

The client settings are in wmf-config/PoolCounterSettings.php:

$wgPoolCountClientConf

 * servers : An array of server IP addresses. Adding multiple servers causes locks to be distributed on the client side using a consistent hashing algorithm.
 * timeout : The connect timeout in seconds.

$wgPoolCounterConf
The key in this configuration array identifies the MediaWiki class which does the work. Currently only parsing is defined, and the parsing job has the ID "ArticleView". The following parameters must be given for each class:


 * class : must be PoolCounter_Client
 * timeout : The amount of time in seconds that a process should wait for a lock before it gives up and takes some other action. In the current implementation, the other action is to return stale HTML to the user, if it is available. If there is no stale cache entry, an error will be shown.
 * workers : The maximum number of processes that may simultaneously hold the lock. Setting this to a value greater than 1 helps to prevent malfunctioning servers from degrading service time, at the expense of wasted CPU.
 * maxqueue : The maximum number of processes that may wait for the lock. If this is exceeded, the effect is the same as an instant timeout. Setting this to a sufficiently low value prevents a lock which is held for a very long period of time from jeopardising the stability of the cluster as a whole.