[JobQueue] Kill ORDER BY in job claim function.
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 12 Dec 2012 23:37:21 +0000 (15:37 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 12 Dec 2012 23:44:00 +0000 (15:44 -0800)
* Although indexed, this slows down for some reason. This started
  to waste master CPU time for wmf wikis with hundreds of thousands
  of jobs. Given how the DB scans the index, the function still
  works correctly without the ORDER BY.

Change-Id: I6ba6cc65d0023de3b9d9df0cfcd6a403289c9848

includes/job/JobQueueDB.php

index c928682..719761b 100644 (file)
@@ -200,7 +200,6 @@ class JobQueueDB extends JobQueue {
         */
        protected function claimRandom( $uuid, $rand, $gte ) {
                $dbw  = $this->getMasterDB();
-               $dir  = $gte ? 'ASC' : 'DESC';
                $ineq = $gte ? '>=' : '<=';
 
                $row = false; // the row acquired
@@ -214,8 +213,8 @@ class JobQueueDB extends JobQueue {
                                        'job_cmd'   => $this->type,
                                        'job_token' => '',
                                        "job_random {$ineq} {$dbw->addQuotes( $rand )}" ),
-                               __METHOD__,
-                               array( 'ORDER BY' => "job_random {$dir}" )
+                               __METHOD__
+                               // Bug 42614: "ORDER BY job_random" causes slowness on mysql for some reason
                        );
                        if ( $row ) { // claim the job
                                $dbw->update( 'job', // update by PK