| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; |
| 22 |
use MediaWiki\Cache\LinkCache; |
| 23 |
use MediaWiki\Config\ServiceOptions; |
| 24 |
use MediaWiki\Deferred\DeferredUpdates; |
| 25 |
use MediaWiki\Http\Telemetry; |
| 26 |
use MediaWiki\MainConfigNames; |
| 27 |
use Psr\Log\LoggerInterface; |
| 28 |
use Wikimedia\Rdbms\DBConnectionError; |
| 29 |
use Wikimedia\Rdbms\DBReadOnlyError; |
| 30 |
use Wikimedia\Rdbms\ILBFactory; |
| 31 |
use Wikimedia\Rdbms\ReadOnlyMode; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
class JobRunner { |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public const CONSTRUCTOR_OPTIONS = [ |
| 45 |
MainConfigNames::JobBackoffThrottling, |
| 46 |
MainConfigNames::JobClasses, |
| 47 |
MainConfigNames::MaxJobDBWriteDuration, |
| 48 |
MainConfigNames::TrxProfilerLimits, |
| 49 |
]; |
| 50 |
|
| 51 |
|
| 52 |
private $options; |
| 53 |
|
| 54 |
|
| 55 |
private $lbFactory; |
| 56 |
|
| 57 |
|
| 58 |
private $jobQueueGroup; |
| 59 |
|
| 60 |
|
| 61 |
private $readOnlyMode; |
| 62 |
|
| 63 |
|
| 64 |
private $linkCache; |
| 65 |
|
| 66 |
|
| 67 |
private $stats; |
| 68 |
|
| 69 |
|
| 70 |
private $debug; |
| 71 |
|
| 72 |
|
| 73 |
private $logger; |
| 74 |
|
| 75 |
|
| 76 |
private const MAX_ALLOWED_LAG = 3; |
| 77 |
|
| 78 |
private const SYNC_TIMEOUT = self::MAX_ALLOWED_LAG; |
| 79 |
|
| 80 |
private const LAG_CHECK_PERIOD = 1.0; |
| 81 |
|
| 82 |
private const ERROR_BACKOFF_TTL = 1; |
| 83 |
|
| 84 |
private const READONLY_BACKOFF_TTL = 30; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public function setDebugHandler( $debug ) { |
| 90 |
$this->debug = $debug; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public function __construct( |
| 104 |
ServiceOptions $serviceOptions, |
| 105 |
ILBFactory $lbFactory, |
| 106 |
JobQueueGroup $jobQueueGroup, |
| 107 |
ReadOnlyMode $readOnlyMode, |
| 108 |
LinkCache $linkCache, |
| 109 |
StatsdDataFactoryInterface $statsdDataFactory, |
| 110 |
LoggerInterface $logger |
| 111 |
) { |
| 112 |
$serviceOptions->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
| 113 |
$this->options = $serviceOptions; |
| 114 |
$this->lbFactory = $lbFactory; |
| 115 |
$this->jobQueueGroup = $jobQueueGroup; |
| 116 |
$this->readOnlyMode = $readOnlyMode; |
| 117 |
$this->linkCache = $linkCache; |
| 118 |
$this->stats = $statsdDataFactory; |
| 119 |
$this->logger = $logger; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public function run( array $options ) { |
| 148 |
$type = $options['type'] ?? false; |
| 149 |
$maxJobs = $options['maxJobs'] ?? false; |
| 150 |
$maxTime = $options['maxTime'] ?? false; |
| 151 |
$throttle = $options['throttle'] ?? true; |
| 152 |
|
| 153 |
$jobClasses = $this->options->get( MainConfigNames::JobClasses ); |
| 154 |
$profilerLimits = $this->options->get( MainConfigNames::TrxProfilerLimits ); |
| 155 |
|
| 156 |
$response = [ 'jobs' => [], 'reached' => 'none-ready' ]; |
| 157 |
|
| 158 |
if ( $type !== false && !isset( $jobClasses[$type] ) ) { |
| 159 |
|
| 160 |
$response['reached'] = 'none-possible'; |
| 161 |
return $response; |
| 162 |
} |
| 163 |
|
| 164 |
if ( $this->readOnlyMode->isReadOnly() ) { |
| 165 |
|
| 166 |
$response['reached'] = 'read-only'; |
| 167 |
return $response; |
| 168 |
} |
| 169 |
|
| 170 |
[ , $maxLag ] = $this->lbFactory->getMainLB()->getMaxLag(); |
| 171 |
if ( $maxLag >= self::MAX_ALLOWED_LAG ) { |
| 172 |
|
| 173 |
$response['reached'] = 'replica-lag-limit'; |
| 174 |
return $response; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
$this->lbFactory->getTransactionProfiler() |
| 179 |
->setExpectations( $profilerLimits['JobRunner'], __METHOD__ ); |
| 180 |
|
| 181 |
|
| 182 |
if ( $this->lbFactory->hasTransactionRound() ) { |
| 183 |
throw new LogicException( __METHOD__ . ' called with an active transaction round.' ); |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
$backoffs = []; |
| 188 |
$backoffDeltas = []; |
| 189 |
$wait = 'wait'; |
| 190 |
|
| 191 |
$loopStartTime = microtime( true ); |
| 192 |
$jobsPopped = 0; |
| 193 |
$timeMsTotal = 0; |
| 194 |
$lastSyncTime = 1; |
| 195 |
|
| 196 |
do { |
| 197 |
|
| 198 |
$backoffs = $this->syncBackoffDeltas( $backoffs, $backoffDeltas, $wait ); |
| 199 |
$backoffKeys = $throttle ? array_keys( $backoffs ) : []; |
| 200 |
$wait = 'nowait'; |
| 201 |
|
| 202 |
if ( $type === false ) { |
| 203 |
|
| 204 |
$job = $this->jobQueueGroup |
| 205 |
->pop( JobQueueGroup::TYPE_DEFAULT, JobQueueGroup::USE_CACHE, $backoffKeys ); |
| 206 |
} else { |
| 207 |
|
| 208 |
|
| 209 |
$job = in_array( $type, $backoffKeys ) ? false : $this->jobQueueGroup->pop( $type ); |
| 210 |
} |
| 211 |
|
| 212 |
if ( $job ) { |
| 213 |
++$jobsPopped; |
| 214 |
$jType = $job->getType(); |
| 215 |
|
| 216 |
|
| 217 |
$ttw = $this->getBackoffTimeToWait( $job ); |
| 218 |
if ( $ttw > 0 ) { |
| 219 |
|
| 220 |
|
| 221 |
$backoffDeltas[$jType] = ( $backoffDeltas[$jType] ?? 0 ) + $ttw; |
| 222 |
$backoffs = $this->syncBackoffDeltas( $backoffs, $backoffDeltas, $wait ); |
| 223 |
} |
| 224 |
|
| 225 |
$info = $this->executeJob( $job ); |
| 226 |
|
| 227 |
|
| 228 |
if ( $info['status'] !== false || !$job->allowRetries() ) { |
| 229 |
$this->jobQueueGroup->ack( $job ); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
if ( $info['status'] === false && mt_rand( 0, 49 ) == 0 ) { |
| 234 |
$ttw = max( $ttw, $this->getErrorBackoffTTL( $info['caught'] ) ); |
| 235 |
$backoffDeltas[$jType] = ( $backoffDeltas[$jType] ?? 0 ) + $ttw; |
| 236 |
} |
| 237 |
|
| 238 |
$response['jobs'][] = [ |
| 239 |
'type' => $jType, |
| 240 |
'status' => ( $info['status'] === false ) ? 'failed' : 'ok', |
| 241 |
'error' => $info['error'], |
| 242 |
'time' => $info['timeMs'] |
| 243 |
]; |
| 244 |
$timeMsTotal += $info['timeMs']; |
| 245 |
|
| 246 |
|
| 247 |
if ( $maxJobs && $jobsPopped >= $maxJobs ) { |
| 248 |
$response['reached'] = 'job-limit'; |
| 249 |
break; |
| 250 |
} elseif ( $maxTime && ( microtime( true ) - $loopStartTime ) > $maxTime ) { |
| 251 |
$response['reached'] = 'time-limit'; |
| 252 |
break; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
if ( in_array( DBConnectionError::class, $info['caught'], true ) ) { |
| 260 |
$response['reached'] = 'exception'; |
| 261 |
break; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
$timePassed = microtime( true ) - $lastSyncTime; |
| 268 |
if ( $timePassed >= self::LAG_CHECK_PERIOD || $timePassed < 0 ) { |
| 269 |
$opts = [ 'ifWritesSince' => $lastSyncTime, 'timeout' => self::SYNC_TIMEOUT ]; |
| 270 |
if ( !$this->lbFactory->waitForReplication( $opts ) ) { |
| 271 |
$response['reached'] = 'replica-lag-limit'; |
| 272 |
break; |
| 273 |
} |
| 274 |
$lastSyncTime = microtime( true ); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
if ( !$this->checkMemoryOK() ) { |
| 279 |
$response['reached'] = 'memory-limit'; |
| 280 |
break; |
| 281 |
} |
| 282 |
} |
| 283 |
} while ( $job ); |
| 284 |
|
| 285 |
|
| 286 |
if ( $backoffDeltas ) { |
| 287 |
$this->syncBackoffDeltas( $backoffs, $backoffDeltas, 'wait' ); |
| 288 |
} |
| 289 |
|
| 290 |
$response['backoffs'] = $backoffs; |
| 291 |
$response['elapsed'] = $timeMsTotal; |
| 292 |
|
| 293 |
return $response; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
public function executeJob( RunnableJob $job ) { |
| 315 |
$telemetry = Telemetry::getInstance(); |
| 316 |
$oldRequestId = $telemetry->getRequestId(); |
| 317 |
|
| 318 |
if ( $job->getRequestId() !== null ) { |
| 319 |
|
| 320 |
$telemetry->overrideRequestId( $job->getRequestId() ); |
| 321 |
} else { |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
$telemetry->regenerateRequestId(); |
| 326 |
} |
| 327 |
|
| 328 |
$oldTimeout = $this->lbFactory->setDefaultReplicationWaitTimeout( self::SYNC_TIMEOUT ); |
| 329 |
try { |
| 330 |
return $this->doExecuteJob( $job ); |
| 331 |
} finally { |
| 332 |
$this->lbFactory->setDefaultReplicationWaitTimeout( $oldTimeout ); |
| 333 |
$telemetry->overrideRequestId( $oldRequestId ); |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
private function doExecuteJob( RunnableJob $job ) { |
| 346 |
$jType = $job->getType(); |
| 347 |
$msg = $job->toString() . " STARTING"; |
| 348 |
$this->logger->debug( $msg, [ 'job_type' => $job->getType() ] ); |
| 349 |
$this->debugCallback( $msg ); |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
$this->linkCache->clear(); |
| 354 |
|
| 355 |
|
| 356 |
$caught = []; |
| 357 |
$rssStart = $this->getMaxRssKb(); |
| 358 |
$jobStartTime = microtime( true ); |
| 359 |
try { |
| 360 |
$fnameTrxOwner = get_class( $job ) . '::run'; |
| 361 |
|
| 362 |
if ( $job->hasExecutionFlag( $job::JOB_NO_EXPLICIT_TRX_ROUND ) ) { |
| 363 |
$this->lbFactory->commitPrimaryChanges( $fnameTrxOwner ); |
| 364 |
} else { |
| 365 |
$this->lbFactory->beginPrimaryChanges( $fnameTrxOwner ); |
| 366 |
} |
| 367 |
|
| 368 |
$status = $job->run(); |
| 369 |
$error = $job->getLastError(); |
| 370 |
|
| 371 |
$this->lbFactory->commitPrimaryChanges( |
| 372 |
$fnameTrxOwner, |
| 373 |
|
| 374 |
$this->options->get( MainConfigNames::MaxJobDBWriteDuration ) |
| 375 |
); |
| 376 |
|
| 377 |
DeferredUpdates::doUpdates(); |
| 378 |
} catch ( Throwable $e ) { |
| 379 |
MWExceptionHandler::rollbackPrimaryChangesAndLog( $e ); |
| 380 |
$status = false; |
| 381 |
$error = get_class( $e ) . ': ' . $e->getMessage() . ' in ' |
| 382 |
. $e->getFile() . ' on line ' . $e->getLine(); |
| 383 |
$caught[] = get_class( $e ); |
| 384 |
} |
| 385 |
|
| 386 |
try { |
| 387 |
$job->tearDown( $status ); |
| 388 |
} catch ( Throwable $e ) { |
| 389 |
MWExceptionHandler::logException( $e ); |
| 390 |
} |
| 391 |
|
| 392 |
$timeMs = intval( ( microtime( true ) - $jobStartTime ) * 1000 ); |
| 393 |
$rssEnd = $this->getMaxRssKb(); |
| 394 |
|
| 395 |
|
| 396 |
$readyTs = $job->getReadyTimestamp(); |
| 397 |
if ( $readyTs ) { |
| 398 |
$pickupDelay = max( 0, $jobStartTime - $readyTs ); |
| 399 |
$this->stats->timing( 'jobqueue.pickup_delay.all', 1000 * $pickupDelay ); |
| 400 |
$this->stats->timing( "jobqueue.pickup_delay.$jType", 1000 * $pickupDelay ); |
| 401 |
} |
| 402 |
|
| 403 |
$rootTimestamp = $job->getRootJobParams()['rootJobTimestamp']; |
| 404 |
if ( $rootTimestamp ) { |
| 405 |
$age = max( 0, $jobStartTime - (int)wfTimestamp( TS_UNIX, $rootTimestamp ) ); |
| 406 |
$this->stats->timing( "jobqueue.pickup_root_age.$jType", 1000 * $age ); |
| 407 |
} |
| 408 |
|
| 409 |
$this->stats->timing( "jobqueue.run.$jType", $timeMs ); |
| 410 |
|
| 411 |
if ( $rssStart && $rssEnd ) { |
| 412 |
$this->stats->updateCount( "jobqueue.rss_delta.$jType", $rssEnd - $rssStart ); |
| 413 |
} |
| 414 |
|
| 415 |
if ( $status === false ) { |
| 416 |
$msg = $job->toString() . " t={job_duration} error={job_error}"; |
| 417 |
$this->logger->error( $msg, [ |
| 418 |
'job_type' => $job->getType(), |
| 419 |
'job_duration' => $timeMs, |
| 420 |
'job_error' => $error, |
| 421 |
] ); |
| 422 |
|
| 423 |
$msg = $job->toString() . " t=$timeMs error={$error}"; |
| 424 |
$this->debugCallback( $msg ); |
| 425 |
} else { |
| 426 |
$msg = $job->toString() . " t={job_duration} good"; |
| 427 |
$this->logger->info( $msg, [ |
| 428 |
'job_type' => $job->getType(), |
| 429 |
'job_duration' => $timeMs, |
| 430 |
] ); |
| 431 |
|
| 432 |
$msg = $job->toString() . " t=$timeMs good"; |
| 433 |
$this->debugCallback( $msg ); |
| 434 |
} |
| 435 |
|
| 436 |
return [ |
| 437 |
'status' => $status, |
| 438 |
'error' => $error, |
| 439 |
'caught' => $caught, |
| 440 |
'timeMs' => $timeMs |
| 441 |
]; |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
private function getErrorBackoffTTL( array $caught ) { |
| 449 |
return in_array( DBReadOnlyError::class, $caught ) |
| 450 |
? self::READONLY_BACKOFF_TTL |
| 451 |
: self::ERROR_BACKOFF_TTL; |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
private function getMaxRssKb() { |
| 458 |
$info = getrusage( 0 ); |
| 459 |
|
| 460 |
return isset( $info['ru_maxrss'] ) ? (int)$info['ru_maxrss'] : null; |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
private function getBackoffTimeToWait( RunnableJob $job ) { |
| 469 |
$throttling = $this->options->get( MainConfigNames::JobBackoffThrottling ); |
| 470 |
|
| 471 |
if ( !isset( $throttling[$job->getType()] ) || $job instanceof DuplicateJob ) { |
| 472 |
return 0; |
| 473 |
} |
| 474 |
|
| 475 |
$itemsPerSecond = $throttling[$job->getType()]; |
| 476 |
if ( $itemsPerSecond <= 0 ) { |
| 477 |
return 0; |
| 478 |
} |
| 479 |
|
| 480 |
$seconds = 0; |
| 481 |
if ( $job->workItemCount() > 0 ) { |
| 482 |
$exactSeconds = $job->workItemCount() / $itemsPerSecond; |
| 483 |
|
| 484 |
$seconds = floor( $exactSeconds ); |
| 485 |
$remainder = $exactSeconds - $seconds; |
| 486 |
$seconds += ( mt_rand() / mt_getrandmax() < $remainder ) ? 1 : 0; |
| 487 |
} |
| 488 |
|
| 489 |
return (int)$seconds; |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
private function loadBackoffs( array $backoffs, $mode = 'wait' ) { |
| 501 |
$file = wfTempDir() . '/mw-runJobs-backoffs.json'; |
| 502 |
if ( is_file( $file ) ) { |
| 503 |
$noblock = ( $mode === 'nowait' ) ? LOCK_NB : 0; |
| 504 |
$handle = fopen( $file, 'rb' ); |
| 505 |
if ( !flock( $handle, LOCK_SH | $noblock ) ) { |
| 506 |
fclose( $handle ); |
| 507 |
return $backoffs; |
| 508 |
} |
| 509 |
$content = stream_get_contents( $handle ); |
| 510 |
flock( $handle, LOCK_UN ); |
| 511 |
fclose( $handle ); |
| 512 |
$ctime = microtime( true ); |
| 513 |
$cBackoffs = json_decode( $content, true ) ?: []; |
| 514 |
foreach ( $cBackoffs as $type => $timestamp ) { |
| 515 |
if ( $timestamp < $ctime ) { |
| 516 |
unset( $cBackoffs[$type] ); |
| 517 |
} |
| 518 |
} |
| 519 |
} else { |
| 520 |
$cBackoffs = []; |
| 521 |
} |
| 522 |
|
| 523 |
return $cBackoffs; |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
private function syncBackoffDeltas( array $backoffs, array &$deltas, $mode = 'wait' ) { |
| 538 |
if ( !$deltas ) { |
| 539 |
return $this->loadBackoffs( $backoffs, $mode ); |
| 540 |
} |
| 541 |
|
| 542 |
$noblock = ( $mode === 'nowait' ) ? LOCK_NB : 0; |
| 543 |
$file = wfTempDir() . '/mw-runJobs-backoffs.json'; |
| 544 |
$handle = fopen( $file, 'wb+' ); |
| 545 |
if ( !flock( $handle, LOCK_EX | $noblock ) ) { |
| 546 |
fclose( $handle ); |
| 547 |
return $backoffs; |
| 548 |
} |
| 549 |
$ctime = microtime( true ); |
| 550 |
$content = stream_get_contents( $handle ); |
| 551 |
$cBackoffs = json_decode( $content, true ) ?: []; |
| 552 |
foreach ( $deltas as $type => $seconds ) { |
| 553 |
$cBackoffs[$type] = isset( $cBackoffs[$type] ) && $cBackoffs[$type] >= $ctime |
| 554 |
? $cBackoffs[$type] + $seconds |
| 555 |
: $ctime + $seconds; |
| 556 |
} |
| 557 |
foreach ( $cBackoffs as $type => $timestamp ) { |
| 558 |
if ( $timestamp < $ctime ) { |
| 559 |
unset( $cBackoffs[$type] ); |
| 560 |
} |
| 561 |
} |
| 562 |
ftruncate( $handle, 0 ); |
| 563 |
fwrite( $handle, json_encode( $cBackoffs ) ); |
| 564 |
flock( $handle, LOCK_UN ); |
| 565 |
fclose( $handle ); |
| 566 |
|
| 567 |
$deltas = []; |
| 568 |
|
| 569 |
return $cBackoffs; |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
private function checkMemoryOK() { |
| 578 |
static $maxBytes = null; |
| 579 |
if ( $maxBytes === null ) { |
| 580 |
$m = []; |
| 581 |
if ( preg_match( '!^(\d+)(k|m|g|)$!i', ini_get( 'memory_limit' ), $m ) ) { |
| 582 |
[ , $num, $unit ] = $m; |
| 583 |
$conv = [ 'g' => 1073741824, 'm' => 1048576, 'k' => 1024, '' => 1 ]; |
| 584 |
$maxBytes = (int)$num * $conv[strtolower( $unit )]; |
| 585 |
} else { |
| 586 |
$maxBytes = 0; |
| 587 |
} |
| 588 |
} |
| 589 |
$usedBytes = memory_get_usage(); |
| 590 |
if ( $maxBytes && $usedBytes >= 0.95 * $maxBytes ) { |
| 591 |
$msg = "Detected excessive memory usage ({used_bytes}/{max_bytes})."; |
| 592 |
$this->logger->error( $msg, [ |
| 593 |
'used_bytes' => $usedBytes, |
| 594 |
'max_bytes' => $maxBytes, |
| 595 |
] ); |
| 596 |
|
| 597 |
$msg = "Detected excessive memory usage ($usedBytes/$maxBytes)."; |
| 598 |
$this->debugCallback( $msg ); |
| 599 |
|
| 600 |
return false; |
| 601 |
} |
| 602 |
|
| 603 |
return true; |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
private function debugCallback( $msg ) { |
| 611 |
if ( $this->debug ) { |
| 612 |
call_user_func_array( $this->debug, [ wfTimestamp( TS_DB ) . " $msg\n" ] ); |
| 613 |
} |
| 614 |
} |
| 615 |
} |