Added $wgTrxProfilerLimits and slow query limits
[lhc/web/wiklou.git] / includes / jobqueue / JobRunner.php
index 1725b74..e9ae30e 100644 (file)
@@ -88,7 +88,7 @@ class JobRunner implements LoggerAwareInterface {
         * @return array Summary response that can easily be JSON serialized
         */
        public function run( array $options ) {
-               global $wgJobClasses;
+               global $wgJobClasses, $wgTrxProfilerLimits;
 
                $response = array( 'jobs' => array(), 'reached' => 'none-ready' );
 
@@ -120,11 +120,13 @@ class JobRunner implements LoggerAwareInterface {
                // Catch huge single updates that lead to slave lag
                $trxProfiler = Profiler::instance()->getTransactionProfiler();
                $trxProfiler->setLogger( LoggerFactory::getInstance( 'DBPerformance' ) );
-               $trxProfiler->setExpectation( 'maxAffected', 500, __METHOD__ );
+               $trxProfiler->setExpectations( $wgTrxProfilerLimits['JobRunner'], __METHOD__ );
 
-               // Bail out if there is too much DB lag
-               list( , $maxLag ) = wfGetLBFactory()->getMainLB( wfWikiID() )->getMaxLag();
-               if ( $maxLag >= 5 ) {
+               // Bail out if there is too much DB lag.
+               // This check should not block as we want to try other wiki queues.
+               $maxAllowedLag = 3;
+               list( , $maxLag ) = wfGetLB( wfWikiID() )->getMaxLag();
+               if ( $maxLag >= $maxAllowedLag ) {
                        $response['reached'] = 'slave-lag-limit';
                        return $response;
                }
@@ -140,10 +142,9 @@ class JobRunner implements LoggerAwareInterface {
                $jobsRun = 0;
                $timeMsTotal = 0;
                $flags = JobQueueGroup::USE_CACHE;
-               $checkPeriod = 5.0; // seconds
-               $checkPhase = mt_rand( 0, 1000 * $checkPeriod ) / 1000; // avoid stampedes
                $startTime = microtime( true ); // time since jobs started running
-               $lastTime = microtime( true ) - $checkPhase; // time since last slave check
+               $checkLagPeriod = 1.0; // check slave lag this many seconds
+               $lastCheckTime = 1; // timestamp of last slave check
                do {
                        // Sync the persistent backoffs with concurrent runners
                        $backoffs = $this->syncBackoffDeltas( $backoffs, $backoffDeltas, $wait );
@@ -234,13 +235,13 @@ class JobRunner implements LoggerAwareInterface {
                                // Don't let any of the main DB slaves get backed up.
                                // This only waits for so long before exiting and letting
                                // other wikis in the farm (on different masters) get a chance.
-                               $timePassed = microtime( true ) - $lastTime;
-                               if ( $timePassed >= 3 || $timePassed < 0 ) {
-                                       if ( !wfWaitForSlaves( $lastTime, false, '*', 5 ) ) {
+                               $timePassed = microtime( true ) - $lastCheckTime;
+                               if ( $timePassed >= $checkLagPeriod || $timePassed < 0 ) {
+                                       if ( !wfWaitForSlaves( $lastCheckTime, false, '*', $maxAllowedLag ) ) {
                                                $response['reached'] = 'slave-lag-limit';
                                                break;
                                        }
-                                       $lastTime = microtime( true );
+                                       $lastCheckTime = microtime( true );
                                }
                                // Don't let any queue slaves/backups fall behind
                                if ( $jobsRun > 0 && ( $jobsRun % 100 ) == 0 ) {