http://www.mediawiki.org/wiki/Special:Code/MediaWiki/56345

Revision: 56345
Author:   brion
Date:     2009-09-14 22:10:10 +0000 (Mon, 14 Sep 2009)

Log Message:
-----------
Merge and clean up memory_limit hacks from wmf-deployment r53208.
Added a memoryLimit() method on Maintenance class which allows scripts to 
override the memory limit; normally we disable the limit but sometimes you 
actually want to set one to avoid eating up RAM on the machine if something 
goes awry.

Modified Paths:
--------------
    trunk/phase3/maintenance/Maintenance.php
    trunk/phase3/maintenance/gearman/gearmanWorker.php
    trunk/phase3/maintenance/rebuildLocalisationCache.php
    trunk/phase3/maintenance/runJobs.php

Modified: trunk/phase3/maintenance/Maintenance.php
===================================================================
--- trunk/phase3/maintenance/Maintenance.php    2009-09-14 22:06:58 UTC (rev 
56344)
+++ trunk/phase3/maintenance/Maintenance.php    2009-09-14 22:10:10 UTC (rev 
56345)
@@ -333,7 +333,7 @@
                }
 
                # Set the memory limit
-               ini_set( 'memory_limit', -1 );
+               ini_set( 'memory_limit', $this->memoryLimit() );
 
                # Set max execution time to 0 (no limit). PHP.net says that
                # "When running PHP from the command line the default setting 
is 0."
@@ -362,6 +362,15 @@
                $this->maybeHelp();
                $this->validateParamsAndArgs();
        }
+       
+       /**
+        * Normally we disable the memory_limit when running admin scripts.
+        * Some scripts may wish to actually set a limit, however, to avoid
+        * blowing up unexpectedly.
+        */
+       public function memoryLimit() {
+               return -1;
+       }
 
        /**
         * Clear all params and arguments.

Modified: trunk/phase3/maintenance/gearman/gearmanWorker.php
===================================================================
--- trunk/phase3/maintenance/gearman/gearmanWorker.php  2009-09-14 22:06:58 UTC 
(rev 56344)
+++ trunk/phase3/maintenance/gearman/gearmanWorker.php  2009-09-14 22:10:10 UTC 
(rev 56345)
@@ -4,6 +4,8 @@
 require( dirname(__FILE__).'/../commandLine.inc' );
 require( dirname(__FILE__).'/gearman.inc' );
 
+ini_set('memory_limit', '150M' );
+
 if ( isset( $options['procs'] ) ) {
        $procs = $options['procs'];
        if ( $procs < 1 || $procs > 1000 ) {

Modified: trunk/phase3/maintenance/rebuildLocalisationCache.php
===================================================================
--- trunk/phase3/maintenance/rebuildLocalisationCache.php       2009-09-14 
22:06:58 UTC (rev 56344)
+++ trunk/phase3/maintenance/rebuildLocalisationCache.php       2009-09-14 
22:10:10 UTC (rev 56345)
@@ -37,12 +37,14 @@
                $this->addOption( 'force', 'Rebuild all files, even ones not 
out of date' );
                $this->addOption( 'threads', 'Fork more than one thread', 
false, true );
        }
+       
+       public function memoryLimit() {
+               return '200M';
+       }
 
        public function execute() {
                global $wgLocalisationCacheConf;
 
-               ini_set( 'memory_limit', '200M' );
-
                $force = $this->hasOption('force');
                $threads = $this->getOption( 'threads', 1 );
                if( $threads < 1 || $threads != intval( $threads ) ) {

Modified: trunk/phase3/maintenance/runJobs.php
===================================================================
--- trunk/phase3/maintenance/runJobs.php        2009-09-14 22:06:58 UTC (rev 
56344)
+++ trunk/phase3/maintenance/runJobs.php        2009-09-14 22:10:10 UTC (rev 
56345)
@@ -36,6 +36,11 @@
                $this->addOption( 'procs', 'Number of processes to use', false, 
true );
                $wgUseNormalUser = true;
        }
+       
+       public function memoryLimit() {
+               // Don't eat all memory on the machine if we get a bad job.
+               return "150M";
+       }
 
        public function execute() {
                global $wgTitle;



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to