MediaWiki
REL1_19
|
When you have many workers (threads/servers) giving service, and a cached item expensive to produce expires, you may get several workers doing the job at the same time. More...
Public Member Functions | |
acquireForAnyone () | |
I want to do this task, but if anyone else does it instead, it's also fine for me. | |
acquireForMe () | |
I want to do this task and I need to do it myself. | |
release () | |
I have successfully finished my task. | |
Static Public Member Functions | |
static | factory ($type, $key) |
Create a Pool counter. | |
Public Attributes | |
$maxqueue | |
$timeout | |
$workers | |
const | DONE = 3 |
const | ERROR = -1 |
const | LOCK_HELD = -5 |
const | LOCKED = 1 |
const | NOT_LOCKED = -2 |
const | QUEUE_FULL = -3 |
const | RELEASED = 2 |
const | TIMEOUT = -4 |
Protected Member Functions | |
__construct ($conf, $type, $key) | |
Protected Attributes | |
$key | |
$key: All workers with the same key share the lock. |
When you have many workers (threads/servers) giving service, and a cached item expensive to produce expires, you may get several workers doing the job at the same time.
Given enough requests and the item expiring fast (non-cacheable, lots of edits...) that single work can end up unfairly using most (all) of the cpu of the pool. This is also known as 'Michael Jackson effect' since this effect triggered on the english wikipedia on the day Michael Jackson died, the biographical article got hit with several edits per minutes and hundreds of read hits.
The PoolCounter provides semaphore semantics for restricting the number of workers that may be concurrently performing such single task.
By default PoolCounter_Stub is used, which provides no locking. You can get a useful one in the PoolCounter extension.
Definition at line 21 of file PoolCounter.php.
PoolCounter::__construct | ( | $ | conf, |
$ | type, | ||
$ | key | ||
) | [protected] |
Definition at line 87 of file PoolCounter.php.
References $key.
PoolCounter::acquireForAnyone | ( | ) | [abstract] |
I want to do this task, but if anyone else does it instead, it's also fine for me.
I will read its cached data.
Reimplemented in PoolCounter_Stub.
PoolCounter::acquireForMe | ( | ) | [abstract] |
I want to do this task and I need to do it myself.
Reimplemented in PoolCounter_Stub.
static PoolCounter::factory | ( | $ | type, |
$ | key | ||
) | [static] |
Create a Pool counter.
This should only be called from the PoolWorks.
$type | |
$key |
Definition at line 76 of file PoolCounter.php.
References $key, and $wgPoolCounterConf.
Referenced by PoolCounterWork\__construct().
PoolCounter::release | ( | ) | [abstract] |
I have successfully finished my task.
Lets another one grab the lock, and returns the workers waiting on acquireForAnyone()
Reimplemented in PoolCounter_Stub.
PoolCounter::$key [protected] |
$key: All workers with the same key share the lock.
$workers: It wouldn't be a good idea to have more than this number of workers doing the task simultaneously. $maxqueue: If this number of workers are already working/waiting, fail instead of wait. $timeout: Maximum time in seconds to wait for the lock.
Definition at line 66 of file PoolCounter.php.
Referenced by __construct(), and factory().
PoolCounter::$maxqueue |
Definition at line 66 of file PoolCounter.php.
PoolCounter::$timeout |
Definition at line 66 of file PoolCounter.php.
PoolCounter::$workers |
Definition at line 66 of file PoolCounter.php.
const PoolCounter::DONE = 3 |
Definition at line 26 of file PoolCounter.php.
Referenced by PoolCounterWork\execute().
const PoolCounter::ERROR = -1 |
Definition at line 28 of file PoolCounter.php.
Referenced by PoolCounterWork\execute().
const PoolCounter::LOCK_HELD = -5 |
Definition at line 32 of file PoolCounter.php.
const PoolCounter::LOCKED = 1 |
Definition at line 24 of file PoolCounter.php.
Referenced by PoolCounter_Stub\acquireForAnyone(), PoolCounter_Stub\acquireForMe(), and PoolCounterWork\execute().
const PoolCounter::NOT_LOCKED = -2 |
Definition at line 29 of file PoolCounter.php.
const PoolCounter::QUEUE_FULL = -3 |
Definition at line 30 of file PoolCounter.php.
Referenced by PoolCounterWork\execute().
const PoolCounter::RELEASED = 2 |
Definition at line 25 of file PoolCounter.php.
Referenced by PoolCounter_Stub\release().
const PoolCounter::TIMEOUT = -4 |
Definition at line 31 of file PoolCounter.php.
Referenced by PoolCounterWork\execute().