Avoid negative JobRunner time stats
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 16 Dec 2015 22:43:12 +0000 (14:43 -0800)
committerOri.livneh <ori@wikimedia.org>
Fri, 18 Dec 2015 02:54:13 +0000 (02:54 +0000)
This can happen in sub-second cases with skew. It makes
graphana tend to see -1 as the min for some time values.

Change-Id: I4e39d8ac29f515fd76548f1a7b64d71a03064407

includes/jobqueue/JobRunner.php

index b121dfe..5666415 100644 (file)
@@ -201,14 +201,14 @@ class JobRunner implements LoggerAwareInterface {
                                // Record how long jobs wait before getting popped
                                $readyTs = $job->getReadyTimestamp();
                                if ( $readyTs ) {
-                                       $pickupDelay = $popTime - $readyTs;
+                                       $pickupDelay = max( 0, $popTime - $readyTs );
                                        $stats->timing( 'jobqueue.pickup_delay.all', 1000 * $pickupDelay );
                                        $stats->timing( "jobqueue.pickup_delay.$jType", 1000 * $pickupDelay );
                                }
                                // Record root job age for jobs being run
                                $root = $job->getRootJobParams();
                                if ( $root['rootJobTimestamp'] ) {
-                                       $age = $popTime - wfTimestamp( TS_UNIX, $root['rootJobTimestamp'] );
+                                       $age = max( 0, $popTime - wfTimestamp( TS_UNIX, $root['rootJobTimestamp'] ) );
                                        $stats->timing( "jobqueue.pickup_root_age.$jType", 1000 * $age );
                                }
                                // Track the execution time for jobs