BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
PoolCounter Class Reference
Inheritance diagram for PoolCounter:

Public Member Functions

 getKey ()
 
 acquireForMe ()
 
 acquireForAnyone ()
 
 release ()
 

Static Public Member Functions

static factory ($type, $key)
 

Public Attributes

const LOCKED = 1
 
const RELEASED = 2
 
const DONE = 3
 
const ERROR = -1
 
const NOT_LOCKED = -2
 
const QUEUE_FULL = -3
 
const TIMEOUT = -4
 
const LOCK_HELD = -5
 

Protected Member Functions

 __construct ($conf, $type, $key)
 
 precheckAcquire ()
 
 onAcquire ()
 
 onRelease ()
 
 hashKeyIntoSlots ($key, $slots)
 

Protected Attributes

 $key
 
 $workers
 
 $slots = 0
 
 $maxqueue
 
 $timeout
 

Detailed Description

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. Only one key can be locked by any PoolCounter instance of a process, except for keys that start with "nowait:". However, only 0 timeouts (non-blocking requests) can be used with "nowait:" keys.

By default PoolCounter_Stub is used, which provides no locking. You can get a useful one in the PoolCounter extension.

Constructor & Destructor Documentation

PoolCounter::__construct (   $conf,
  $type,
  $key 
)
protected
Parameters
array$conf
string$type
string$key

Member Function Documentation

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.

Returns
Status Value is one of Locked/Done/Error
PoolCounter::acquireForMe ( )
abstract

I want to do this task and I need to do it myself.

Returns
Status Value is one of Locked/Error
static PoolCounter::factory (   $type,
  $key 
)
static

Create a Pool counter. This should only be called from the PoolWorks.

Parameters
string$type
string$key
Returns
PoolCounter
PoolCounter::getKey ( )
Returns
string
PoolCounter::hashKeyIntoSlots (   $key,
  $slots 
)
protected

Given a key (any string) and the number of lots, returns a slot number (an integer from the [0..($slots-1)] range). This is used for a global limit on the number of instances of a given type that can acquire a lock. The hashing is deterministic so that PoolCounter::$workers is always an upper limit of how many instances with the same key can acquire a lock.

Parameters
string$keyPoolCounter instance key (any string)
int$slotsThe number of slots (max allowed value is 65536)
Returns
int
PoolCounter::onAcquire ( )
finalprotected

Update any lock tracking information when the lock is acquired

Since
1.25
PoolCounter::onRelease ( )
finalprotected

Update any lock tracking information when the lock is released

Since
1.25
PoolCounter::precheckAcquire ( )
finalprotected

Checks that the lock request is sane.

Returns
Status - good for sane requests fatal for insane
Since
1.25
PoolCounter::release ( )
abstract

I have successfully finished my task. Lets another one grab the lock, and returns the workers waiting on acquireForAnyone()

Returns
Status Value is one of Released/NotLocked/Error

The documentation for this class was generated from the following file: