Added per-wiki queue stats information
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 3 Apr 2014 00:25:14 +0000 (17:25 -0700)
committerOri.livneh <ori@wikimedia.org>
Thu, 3 Apr 2014 21:42:10 +0000 (21:42 +0000)
Change-Id: I25f42408c9a7a368aa99f4ceb04214f188a74be6

includes/jobqueue/JobQueue.php
includes/jobqueue/JobQueueDB.php
includes/jobqueue/JobQueueRedis.php

index a537861..2d7103c 100644 (file)
@@ -376,7 +376,7 @@ abstract class JobQueue {
                // Flag this job as an old duplicate based on its "root" job...
                try {
                        if ( $job && $this->isRootJobOldDuplicate( $job ) ) {
-                               JobQueue::incrStats( 'job-pop-duplicate', $this->type );
+                               JobQueue::incrStats( 'job-pop-duplicate', $this->type, 1, $this->wiki );
                                $job = DuplicateJob::newFromJob( $job ); // convert to a no-op
                        }
                } catch ( MWException $e ) {
@@ -715,11 +715,15 @@ abstract class JobQueue {
         * @param string $key Event type
         * @param string $type Job type
         * @param int $delta
+        * @param string $wiki Wiki ID (added in 1.23)
         * @since 1.22
         */
-       public static function incrStats( $key, $type, $delta = 1 ) {
+       public static function incrStats( $key, $type, $delta = 1, $wiki = null ) {
                wfIncrStats( $key, $delta );
                wfIncrStats( "{$key}-{$type}", $delta );
+               if ( $wiki !== null ) {
+                       wfIncrStats( "{$key}-{$type}-{$wiki}", $delta );
+               }
        }
 
        /**
index e83c26d..5f1ca14 100644 (file)
@@ -258,11 +258,12 @@ class JobQueueDB extends JobQueue {
                        foreach ( array_chunk( $rows, 50 ) as $rowBatch ) {
                                $dbw->insert( 'job', $rowBatch, $method );
                        }
-                       JobQueue::incrStats( 'job-insert', $this->type, count( $rows ) );
+                       JobQueue::incrStats( 'job-insert', $this->type, count( $rows ), $this->wiki );
                        JobQueue::incrStats(
                                'job-insert-duplicate',
                                $this->type,
-                               count( $rowSet ) + count( $rowList ) - count( $rows )
+                               count( $rowSet ) + count( $rowList ) - count( $rows ),
+                               $this->wiki
                        );
                } catch ( DBError $e ) {
                        if ( $flags & self::QOS_ATOMIC ) {
@@ -313,7 +314,7 @@ class JobQueueDB extends JobQueue {
                                        $this->cache->set( $this->getCacheKey( 'empty' ), 'true', self::CACHE_TTL_LONG );
                                        break; // nothing to do
                                }
-                               JobQueue::incrStats( 'job-pop', $this->type );
+                               JobQueue::incrStats( 'job-pop', $this->type, 1, $this->wiki );
                                // Get the job object from the row...
                                $title = Title::makeTitleSafe( $row->job_namespace, $row->job_title );
                                if ( !$title ) {
@@ -684,8 +685,9 @@ class JobQueueDB extends JobQueue {
                                                        'job_id' => $ids ),
                                                __METHOD__
                                        );
-                                       $count += $dbw->affectedRows();
-                                       JobQueue::incrStats( 'job-recycle', $this->type, $dbw->affectedRows() );
+                                       $affected = $dbw->affectedRows();
+                                       $count += $affected;
+                                       JobQueue::incrStats( 'job-recycle', $this->type, $affected, $this->wiki );
                                        $this->cache->set( $this->getCacheKey( 'empty' ), 'false', self::CACHE_TTL_LONG );
                                }
                        }
@@ -710,8 +712,9 @@ class JobQueueDB extends JobQueue {
                        );
                        if ( count( $ids ) ) {
                                $dbw->delete( 'job', array( 'job_id' => $ids ), __METHOD__ );
-                               $count += $dbw->affectedRows();
-                               JobQueue::incrStats( 'job-abandon', $this->type, $dbw->affectedRows() );
+                               $affected = $dbw->affectedRows();
+                               $count += $affected;
+                               JobQueue::incrStats( 'job-abandon', $this->type, $affected, $this->wiki );
                        }
 
                        $dbw->unlock( "jobqueue-recycle-{$this->type}", __METHOD__ );
index c785cb2..135a61d 100644 (file)
@@ -237,9 +237,9 @@ class JobQueueRedis extends JobQueue {
 
                                return false;
                        }
-                       JobQueue::incrStats( 'job-insert', $this->type, count( $items ) );
+                       JobQueue::incrStats( 'job-insert', $this->type, count( $items ), $this->wiki );
                        JobQueue::incrStats( 'job-insert-duplicate', $this->type,
-                               count( $items ) - $failed - $pushed );
+                               count( $items ) - $failed - $pushed, $this->wiki );
                } catch ( RedisException $e ) {
                        $this->throwRedisException( $conn, $e );
                }
@@ -331,7 +331,7 @@ LUA;
                                        break; // no jobs; nothing to do
                                }
 
-                               JobQueue::incrStats( 'job-pop', $this->type );
+                               JobQueue::incrStats( 'job-pop', $this->type, 1, $this->wiki );
                                $item = $this->unserialize( $blob );
                                if ( $item === false ) {
                                        wfDebugLog( 'JobQueueRedis', "Could not unserialize {$this->type} job." );
@@ -715,8 +715,8 @@ LUA;
                        if ( $res ) {
                                list( $released, $abandoned, $pruned, $undelayed ) = $res;
                                $count += $released + $pruned + $undelayed;
-                               JobQueue::incrStats( 'job-recycle', $this->type, $released );
-                               JobQueue::incrStats( 'job-abandon', $this->type, $abandoned );
+                               JobQueue::incrStats( 'job-recycle', $this->type, $released, $this->wiki );
+                               JobQueue::incrStats( 'job-abandon', $this->type, $abandoned, $this->wiki );
                        }
                } catch ( RedisException $e ) {
                        $this->throwRedisException( $conn, $e );