X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=blobdiff_plain;f=maintenance%2FMaintenance.php;h=68c51a8839ea48e1d15dee63f88b975e046ad04e;hb=251a0b97e5bb8711bac1784e90f9b7d61377e7da;hp=a3e0ffd9173ae590ca55f1d171f853eee11f4c2d;hpb=1a40e0cc86b6ee0706606ded3ea243dfde4a414c;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index a3e0ffd917..68c51a8839 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -381,6 +381,11 @@ abstract class Maintenance { * @param mixed $channel Unique identifier for the channel. See function outputChanneled. */ protected function output( $out, $channel = null ) { + // Try to periodically flush buffered metrics to avoid OOMs + $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); + if ( $stats->getDataCount() > 1000 ) { + MediaWiki::emitBufferedStatsdData( $stats, $this->getConfig() ); + } if ( $this->mQuiet ) { return; } @@ -405,7 +410,7 @@ abstract class Maintenance { $this->fatalError( $err, intval( $die ) ); } $this->outputChanneled( false ); - if ( PHP_SAPI == 'cli' ) { + if ( PHP_SAPI == 'cli' || PHP_SAPI == 'phpdbg' ) { fwrite( STDERR, $err . "\n" ); } else { print $err; @@ -591,36 +596,41 @@ abstract class Maintenance { $lbFactory->setAgentName( mb_strlen( $agent ) > 15 ? mb_substr( $agent, 0, 15 ) . '...' : $agent ); - self::setLBFactoryTriggers( $lbFactory ); + self::setLBFactoryTriggers( $lbFactory, $this->getConfig() ); } /** * @param LBFactory $LBFactory + * @param Config $config * @since 1.28 */ - public static function setLBFactoryTriggers( LBFactory $LBFactory ) { + public static function setLBFactoryTriggers( LBFactory $LBFactory, Config $config ) { + $services = MediaWikiServices::getInstance(); + $stats = $services->getStatsdDataFactory(); // Hook into period lag checks which often happen in long-running scripts - $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lbFactory = $services->getDBLoadBalancerFactory(); $lbFactory->setWaitForReplicationListener( __METHOD__, - function () { - global $wgCommandLineMode; + function () use ( $stats, $config ) { // Check config in case of JobRunner and unit tests - if ( $wgCommandLineMode ) { + if ( $config->get( 'CommandLineMode' ) ) { DeferredUpdates::tryOpportunisticExecute( 'run' ); } + // Try to periodically flush buffered metrics to avoid OOMs + MediaWiki::emitBufferedStatsdData( $stats, $config ); } ); // Check for other windows to run them. A script may read or do a few writes // to the master but mostly be writing to something else, like a file store. $lbFactory->getMainLB()->setTransactionListener( __METHOD__, - function ( $trigger ) { - global $wgCommandLineMode; + function ( $trigger ) use ( $stats, $config ) { // Check config in case of JobRunner and unit tests - if ( $wgCommandLineMode && $trigger === IDatabase::TRIGGER_COMMIT ) { + if ( $config->get( 'CommandLineMode' ) && $trigger === IDatabase::TRIGGER_COMMIT ) { DeferredUpdates::tryOpportunisticExecute( 'run' ); } + // Try to periodically flush buffered metrics to avoid OOMs + MediaWiki::emitBufferedStatsdData( $stats, $config ); } ); } @@ -662,7 +672,8 @@ abstract class Maintenance { global $IP, $wgCommandLineMode, $wgRequestTime; # Abort if called from a web server - if ( PHP_SAPI !== 'cli' ) { + # wfIsCLI() is not available yet + if ( PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ) { $this->fatalError( 'This script must be run from the command line' ); }