Manual:$wgPoolCounterConf

From MediaWiki.org
Jump to: navigation, search

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎italiano • ‎日本語 • ‎polski • ‎português • ‎português do Brasil • ‎中文
Miscellaneous settings: $wgPoolCounterConf
Configuration for processing pool control.
Introduced in version: 1.16.0 (r52888)
Removed in version: still in use
Allowed values: array or null
Default value: null
Other settings: Alphabetical | By function

Details[edit]

Configuration for processing pool control, for use in high-traffic wikis.

This configuration array maps pool types to client configurations. A client configuration is an associative array with a class key giving the class name of the client (which should be a subclass of PoolCounter), and any other elements which are passed through to the class constructor. The constructor receives three arguments: the configuration array, the pool type and a queue name. (The pool type is used to identify the type of work. The queue name determines which requests are trying to do the same work. E.g. the pool type could be article rendering, and the queue name the ID of the revision which is being rendered.)

An implementation using Redis (PoolCounterRedis) is included with MediaWiki, and another one using a C daemon (PoolCounter_Client) is available in Extension:PoolCounterExtension:PoolCounter.

Configuration options shared by all client[edit]

timeout
Wait timeout in seconds.
workers
Maximum number of active threads in each pool. Additional workers will wait until a place is freed up.
maxqueue
Maximum number of total threads in each pool. (If this number of workers are already working/waiting, fail instead of wait)
slots
Maximum number of workers working on this task type, regardless of queue name. 0 means unlimited. Max allowed value is 65536. The way the slot limit is enforced is overzealous - this option should be used with caution.

Additional configuration options for the Redis implementation[edit]

servers
List of Redis server addresses.
redisConfig
Extra configuration array for RedisConnectionPool.

Usage[edit]

To use PoolCounter, subclass the PoolCounterWork class (or use PoolCounterWorkViaCallback which can implement arbitrary functionality with anonymous functions). Three methods/callbacks can be implemented:

doWork()
called when the worker is the first to work on the given task (also when the PoolCounter server is down). Returns the result of the work.
getCachedWork()
called when the worker had to wait on another worker and that worker has finished. Can be used to get a result that has been cached by doWork(). If not implemented or returns false, doWork() will be called.
fallback()
called on wait timeout or when there are too many workers waiting already. Can be used to return some not so good but cheap result (e.g. showing a cached older revision instead of rendering the new one). If not implemented or returns false, error() will be called.
error()
Can be used to show an error.

Example[edit]

Example configuration:

$wgPoolCounterConf = [
    'FileRender' => [
        'class' => 'PoolCounter_Client',
        'timeout' => 8,
        'workers' => 2,
        'maxqueue' => 100,
    ],
];

Example of using PoolCounter:

// get a thumbnail for $file
$work = new PoolCounterWorkViaCallback( 'FileRender', sha1( $file->getName() ), [
    'doWork' => function () use ( $file, $params ) {
        return $file->transform( $params, File::RENDER_NOW );
    },
    'doCachedWork' => function () use ( $file, $params, $thumbPath ) {
        return $file->getRepo()->fileExists( $thumbPath ) ? $file->transform( $params, File::RENDER_NOW ) : false;
    },
    'error' => function ( Status $status ) {
        return wfMessage( 'generic-pool-error' )->parse() . '<hr>' . $status->getHTML();
    }
] );
$result = $work->execute();

See also[edit]