Track memory RSS increases in JobRunner
Bug: T123284 Change-Id: Ic6b76a722cc8d1e18a42b9779f776850ae4700f4
This commit is contained in:
parent
5d44a604ab
commit
159e71f6d2
1 changed files with 15 additions and 0 deletions
|
|
@ -251,6 +251,7 @@ class JobRunner implements LoggerAwareInterface {
|
|||
$this->debugCallback( $msg );
|
||||
|
||||
// Run the job...
|
||||
$rssStart = $this->getMaxRssKb();
|
||||
$jobStartTime = microtime( true );
|
||||
try {
|
||||
$status = $job->run();
|
||||
|
|
@ -272,6 +273,7 @@ class JobRunner implements LoggerAwareInterface {
|
|||
// Clear out title cache data from prior snapshots
|
||||
LinkCache::singleton()->clear();
|
||||
$timeMs = intval( ( microtime( true ) - $jobStartTime ) * 1000 );
|
||||
$rssEnd = $this->getMaxRssKb();
|
||||
|
||||
// Record how long jobs wait before getting popped
|
||||
$readyTs = $job->getReadyTimestamp();
|
||||
|
|
@ -288,6 +290,10 @@ class JobRunner implements LoggerAwareInterface {
|
|||
}
|
||||
// Track the execution time for jobs
|
||||
$stats->timing( "jobqueue.run.$jType", $timeMs );
|
||||
// Track RSS increases for jobs (in case of memory leaks)
|
||||
if ( $rssStart && $rssEnd ) {
|
||||
$stats->increment( "jobqueue.rss_delta.$jType", $rssEnd - $rssStart );
|
||||
}
|
||||
|
||||
if ( $status === false ) {
|
||||
$msg = $job->toString() . " t=$timeMs error={$error}";
|
||||
|
|
@ -302,6 +308,15 @@ class JobRunner implements LoggerAwareInterface {
|
|||
return array( 'status' => $status, 'error' => $error, 'timeMs' => $timeMs );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null Max memory RSS in kilobytes
|
||||
*/
|
||||
private function getMaxRssKb() {
|
||||
$info = wfGetRusage() ?: array();
|
||||
// see http://linux.die.net/man/2/getrusage
|
||||
return isset( $info['ru_maxrss'] ) ? (int)$info['ru_maxrss'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @return int Seconds for this runner to avoid doing more jobs of this type
|
||||
|
|
|
|||
Loading…
Reference in a new issue