[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/poolcounter/ -> PoolCounterRedis.php (summary)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Author: Aaron Schulz
File Size: 417 lines (14 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

PoolCounterRedis:: (13 methods):
  __construct()
  getConnection()
  acquireForMe()
  acquireForAnyone()
  release()
  waitForSlotOrNotif()
  initAndPopPoolSlotList()
  registerAcquisitionTime()
  getSlotListKey()
  getSlotRTimeSetKey()
  getWaitSetKey()
  getWakeupListKey()
  releaseAll()


Class: PoolCounterRedis  - X-Ref

Version of PoolCounter that uses Redis

There are four main redis keys used to track each pool counter key:
- poolcounter:l-slots-*     : A list of available slot IDs for a pool.
- poolcounter:z-renewtime-* : A sorted set of (slot ID, UNIX timestamp as score)
used for tracking the next time a slot should be
released. This is -1 when a slot is created, and is
set when released (expired), locked, and unlocked.
- poolcounter:z-wait-*      : A sorted set of (slot ID, UNIX timestamp as score)
used for tracking waiting processes (and wait time).
- poolcounter:l-wakeup-*    : A list pushed to for the sake of waking up processes
when a any process in the pool finishes (lasts for 1ms).
For a given pool key, all the redis keys start off non-existing and are deleted if not
used for a while to prevent garbage from building up on the server. They are atomically
re-initialized as needed. The "z-renewtime" key is used for detecting sessions which got
slots but then disappeared. Stale entries from there have their timestamp updated and the
corresponding slots freed up. The "z-wait" key is used for detecting processes registered
as waiting but that disappeared. Stale entries from there are deleted and the corresponding
slots are freed up. The worker count is included in all the redis key names as it does not
vary within each $wgPoolCounterConf type and doing so handles configuration changes.

This class requires Redis 2.6 as it makes use Lua scripts for fast atomic operations.
Also this should be on a server plenty of RAM for the working set to avoid evictions.
Evictions could temporarily allow wait queues to double in size or temporarily cause
pools to appear as full when they are not. Using volatile-ttl and bumping memory-samples
in redis.conf can be helpful otherwise.

__construct( $conf, $type, $key )   X-Ref
No description

getConnection()   X-Ref

return: Status Uses RediConnRef as value on success

acquireForMe()   X-Ref
No description

acquireForAnyone()   X-Ref
No description

release()   X-Ref
No description

waitForSlotOrNotif( $doWakeup )   X-Ref

param: int $doWakeup AWAKE_* constant
return: Status

initAndPopPoolSlotList( RedisConnRef $conn, $now )   X-Ref

param: RedisConnRef $conn
param: float $now UNIX timestamp
return: string|bool False on failure

registerAcquisitionTime( RedisConnRef $conn, $slot, $now )   X-Ref

param: RedisConnRef $conn
param: string $slot
param: float $now
return: int|bool False on failure

getSlotListKey()   X-Ref

return: string

getSlotRTimeSetKey()   X-Ref

return: string

getWaitSetKey()   X-Ref

return: string

getWakeupListKey()   X-Ref

return: string

releaseAll()   X-Ref
Try to make sure that locks get released (even with exceptions and fatals)




Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1