|
[MediaWiki-CVS] SVN: [54084] trunk/phase3/maintenance/rebuildLocalisationCa: msg#01462mediawiki-cvs
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/54084 Revision: 54084 Author: nikerabbit Date: 2009-07-31 09:57:59 +0000 (Fri, 31 Jul 2009) Log Message: ----------- Added --threads=N parameter Modified Paths: -------------- trunk/phase3/maintenance/rebuildLocalisationCache.php Modified: trunk/phase3/maintenance/rebuildLocalisationCache.php =================================================================== --- trunk/phase3/maintenance/rebuildLocalisationCache.php 2009-07-31 09:55:23 UTC (rev 54083) +++ trunk/phase3/maintenance/rebuildLocalisationCache.php 2009-07-31 09:57:59 UTC (rev 54084) @@ -8,12 +8,14 @@ * php rebuildLocalisationCache.php [--force] * * Use --force to rebuild all files, even the ones that are not out of date. + * Use --threads=N to fork more threads. */ require( dirname(__FILE__).'/commandLine.inc' ); ini_set( 'memory_limit', '200M' ); $force = isset( $options['force'] ); +$threads = intval( isset( $options['threads'] ) ? $options['threads'] : 1 ); $conf = $wgLocalisationCacheConf; $conf['manualRecache'] = false; // Allow fallbacks to create CDB files @@ -24,18 +26,44 @@ $codes = array_keys( Language::getLanguageNames( true ) ); sort( $codes ); + +// Initialise and split into chunks $numRebuilt = 0; -foreach ( $codes as $code ) { - if ( $force || $lc->isExpired( $code ) ) { - echo "Rebuilding $code...\n"; - $lc->recache( $code ); - $numRebuilt++; +$total = count($codes); +$chunks = array_chunk( $codes, ceil(count($codes)/$threads) ); +$pids = array(); + +foreach ( $chunks as $codes ) { + // Do not fork for only one thread + $pid = ( $threads > 1 ) ? pcntl_fork() : -1; + + if ( $pid === 0 ) { + // Child + doRebuild( $codes, $numRebuilt, $lc, $force ); + exit(); + } elseif ($pid === -1) { + // Fork failed or one thread, do it serialized + doRebuild( $codes, $numRebuilt, $lc, $force ); + } else { + // Main thread + $pids[] = $pid; } } -echo "$numRebuilt languages rebuilt out of " . count( $codes ) . ".\n"; + +// Wait for all children +foreach ( $pids as $pid ) pcntl_waitpid($pid, $status); + +echo "$numRebuilt languages rebuilt out of $total.\n"; if ( $numRebuilt == 0 ) { echo "Use --force to rebuild the caches which are still fresh.\n"; } - - +function doRebuild( $codes, &$numRebuilt, $lc, $force ) { + foreach ( $codes as $code ) { + if ( $force || $lc->isExpired( $code ) ) { + echo "Rebuilding $code...\n"; + $lc->recache( $code ); + $numRebuilt++; + } + } +} _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@xxxxxxxxxxxxxxxxxxx https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
|
|
||||||||||||||||||||||||||
|
|
|
| News | Mail Home | sitemap | FAQ | advertise |