From: Aaron Schulz Date: Mon, 11 Jan 2016 21:13:21 +0000 (-0800) Subject: Track memory RSS increases in JobRunner X-Git-Tag: 1.31.0-rc.0~8363 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/?a=commitdiff_plain;h=159e71f6d22c4eacc07eea7e7ac4da6e789a792d;p=lhc%2Fweb%2Fwiklou.git Track memory RSS increases in JobRunner Bug: T123284 Change-Id: Ic6b76a722cc8d1e18a42b9779f776850ae4700f4 --- diff --git a/includes/jobqueue/JobRunner.php b/includes/jobqueue/JobRunner.php index a6d088fe52..4ab9f5ad2e 100644 --- a/includes/jobqueue/JobRunner.php +++ b/includes/jobqueue/JobRunner.php @@ -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