[JobQueue] Optimized redis queue to use Lua scripts.
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 13 Mar 2013 21:26:28 +0000 (14:26 -0700)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 20 Mar 2013 01:04:53 +0000 (01:04 +0000)
commitcc3ac23c4fec3f85d65563d0a4bb642774cecf7e
tree9b492b4cdc934649bafdfcf3c816d9876e095db1
parentadffdf3929ffb4b5a819c3ac097a0d89a3ee636b
[JobQueue] Optimized redis queue to use Lua scripts.

* Cleaned up some data structures into hashes, which get better
  compression and play well with the KEYS parameter in Lua scripts.
  The claim list is now a sorted set with O(logN) removal in ack()
  and O(log(N)+M) searching in recycleAndDeleteStaleJobs().
* Made the class itself control object serialization, so that lua
  scripts have an easy time. Only the job data itself needs to be
  serialized, where as other things just get bloated.
* Used Lua scripts to get push(), pop() and ack() down to 1 RTT.
* Likewise rewrote recycleAndDeleteStaleJobs() to use a script.
* Fixed bug where claimed duplicate jobs removed the data on ack(),
  which meant that claimed duplicated jobs could no-op newer ones.
  De-duplication should only apply to unclaimed jobs like for the
  JobQueueDB class, so that unfinished jobs don't no-op new ones.
* Removed locking in recycleAndDeleteStaleJobs(), which would not do
  much since the exclusive set request would serialize on the lua
  script anyway. The lua script will finish quickly the next times
  if done more than once in a row due to sorted set usage.
  Also made recycleAndDeleteStaleJobs() run randomly to reduce the
  chance of a single calling tying up the server.
* Removed useless hDel() call in getJobFromUidInternal().
* Changed unit tests to handle the different supported orders better.
  Added tests for the 'timestamp' ordering.

Change-Id: Ib2d7aff18753195248ab856afd4a46e18b301db9
includes/job/JobQueueRedis.php
tests/phpunit/includes/jobqueue/JobQueueTest.php