From: Aaron Schulz Date: Tue, 8 Apr 2014 16:34:49 +0000 (-0700) Subject: Avoid making a derivative request to Special:RunJobs when the job queue is empty X-Git-Tag: 1.31.0-rc.0~16295 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=4865e34630fca77e9b277c015a723b103ba6fb3e;p=lhc%2Fweb%2Fwiklou.git Avoid making a derivative request to Special:RunJobs when the job queue is empty Checking that the job queue is nonempty is cheap, and when the result is negative (that is, when the queue is actually empty), it spares from having to launch a derivative request to Special:RunJobs for job processing. The derivative request is not cheap, because processing it requires having an additional full instance of the application. This patch adds the check. Bug: 60210 Change-Id: Icb95c35f4a8a3c9d4b5aff97fdfabf596d05940a --- diff --git a/includes/Wiki.php b/includes/Wiki.php index ccc9b8d146..fbafba8139 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -651,6 +651,10 @@ class MediaWiki { return; } + if ( !JobQueueGroup::singleton()->queuesHaveJobs( JobQueueGroup::TYPE_DEFAULT ) ) { + return; // do not send request if there are probably no jobs + } + $query = array( 'title' => 'Special:RunJobs', 'tasks' => 'jobs', 'maxjobs' => $n, 'sigexpiry' => time() + 5 ); $query['signature'] = SpecialRunJobs::getQuerySignature( $query ); diff --git a/includes/jobqueue/JobQueueGroup.php b/includes/jobqueue/JobQueueGroup.php index 90742ced39..b1dfe14966 100644 --- a/includes/jobqueue/JobQueueGroup.php +++ b/includes/jobqueue/JobQueueGroup.php @@ -254,6 +254,31 @@ class JobQueueGroup { return array_diff( $this->getQueueTypes(), $wgJobTypesExcludedFromDefaultQueue ); } + /** + * Check if there are any queues with jobs (this is cached) + * + * @param integer $type JobQueueGroup::TYPE_* constant + * @return bool + * @since 1.23 + */ + public function queuesHaveJobs( $type = self::TYPE_ANY ) { + global $wgMemc; + + $key = wfMemcKey( 'jobqueue', 'queueshavejobs', $type ); + + $value = $wgMemc->get( $key ); + if ( $value === false ) { + $queues = $this->getQueuesWithJobs(); + if ( $type == self::TYPE_DEFAULT ) { + $queues = array_intersect( $queues, $this->getDefaultQueueTypes() ); + } + $value = count( $queues ) ? 'true' : 'false'; + $wgMemc->add( $key, $value, 15 ); + } + + return ( $value === 'true' ); + } + /** * Get the list of job types that have non-empty queues *