++$jobsRun;
$this->runJobsLog( $job->toString() . " STARTING" );
- // Set timer to stop the job if too much CPU time is used
- set_time_limit( $maxTime ? : 0 );
// Run the job...
wfProfileIn( __METHOD__ . '-' . get_class( $job ) );
$t = microtime( true );
}
$timeMs = intval( ( microtime( true ) - $t ) * 1000 );
wfProfileOut( __METHOD__ . '-' . get_class( $job ) );
- // Disable the timer
- set_time_limit( 0 );
// Mark the job as done on success or when the job cannot be retried
if ( $status !== false || !$job->allowRetries() ) {
$this->runJobsLog( $job->toString() . " t=$timeMs good" );
}
- // Back off of certain jobs for a while
+ // Back off of certain jobs for a while (for throttling and for errors)
$ttw = $this->getBackoffTimeToWait( $job );
+ if ( $status === false && mt_rand( 0, 49 ) == 0 ) {
+ $ttw = max( $ttw, 30 );
+ }
if ( $ttw > 0 ) {
$jType = $job->getType();
$backoffs[$jType] = isset( $backoffs[$jType] ) ? $backoffs[$jType] : 0;
$seconds = 0;
if ( $job->workItemCount() > 0 ) {
- $seconds = floor( $job->workItemCount() / $itemsPerSecond );
- $remainder = $job->workItemCount() % $itemsPerSecond;
- $seconds += ( mt_rand( 1, $itemsPerSecond ) <= $remainder ) ? 1 : 0;
+ $exactSeconds = $job->workItemCount() / $itemsPerSecond;
+ // use randomized rounding
+ $seconds = floor( $exactSeconds );
+ $remainder = $exactSeconds - $seconds;
+ $seconds += ( mt_rand() / mt_getrandmax() < $remainder ) ? 1 : 0;
}
return (int)$seconds;