Jump to content


From mediawiki.org
This page is a translated version of the page Manual:$wgPoolCounterConf and the translation is 0% complete.
Performans hileleri ve sınırları: $wgPoolCounterConf
Configuration for processing pool control.
Sürümde tanıtıldı:1.16.0 (r52888)
Sürümde kaldırıldı:hala kullanımda
İzin verilen değerler:(array) or null
Varsayılan değer:null


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 PoolCounter#Configuration.

Pool types

Pool types that can be used as keys for the $wgPoolCounterConf array. More types can be made available by extensions:

When rendering the contents of a page that it's not in parser cache (including old versions of a page).
When retrieving a file of more than 10MB to local path for thumbnailing.
When rendering a diff, if the size of the old and new text is greater than 20000 characters.
When thumbnailing a file that is considered expensive to thumbnail. The consideration of expensive depends on the file type and image or media dimensions. Only applies to thumbnails rendered directly from thumb.php.
When thumbnailing a file. Only applies to thumbnails rendered directly from thumb.php.
When parsing wikitext through the api.
When rendering Special:Contributions.

Configuration options shared by all client

Wait timeout in seconds.
Maximum number of active threads in each pool. Additional workers will wait until a place is freed up.
Maximum number of total threads in each pool. (If this number of workers are already working/waiting, fail instead of wait)
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

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


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

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.
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.
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.
Can be used to show an error.


Example configuration:

$wgPoolCountClientConf = [
    'servers' => [ '' ],
    'timeout' => 0.5,
    'connect_timeout' => 0.01,
$wgPoolCounterConf = [
    'ArticleView' => [
        'class' => MediaWiki\PoolCounter\PoolCounterClient::class,
        'timeout' => 15, // wait timeout in seconds
        'workers' => 5, // maximum number of active threads in each pool
        'maxqueue' => 50, // maximum number of total threads in each pool

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();

Example using redis

$wgPoolCounterConf = [ 
        'ArticleView' => [
                'class' => 'PoolCounterRedis',
                'timeout' => 300, // wait timeout in seconds
                'workers' => 1, // maximum number of active threads in each pool
                'maxqueue' => 2, // maximum number of total threads in each pool
                'servers' => [ '' ],
                'redisConfig' => [],

See also