MediaWiki  REL1_21
fileOpPerfTest.php
Go to the documentation of this file.
00001 <?php
00024 $wgProfiler = array( 'class' => 'ProfilerSimpleText' );
00025 error_reporting( E_ALL );
00026 
00027 require_once( __DIR__ . '/Maintenance.php' );
00028 
00034 class TestFileOpPerformance extends Maintenance {
00035         public function __construct() {
00036                 parent::__construct();
00037                 $this->mDescription = "Test fileop performance";
00038                 $this->addOption( 'b1', 'Backend 1', true, true );
00039                 $this->addOption( 'b2', 'Backend 2', false, true );
00040                 $this->addOption( 'srcdir', 'File source directory', true, true );
00041                 $this->addOption( 'maxfiles', 'Max files', false, true );
00042                 $this->addOption( 'quick', 'Avoid operation pre-checks (use doQuickOperations())' );
00043                 $this->addOption( 'parallelize', '"parallelize" flag for doOperations()', false, true );
00044         }
00045 
00046         public function execute() {
00047                 $backend = FileBackendGroup::singleton()->get( $this->getOption( 'b1' ) );
00048                 $this->doPerfTest( $backend );
00049 
00050                 if ( $this->getOption( 'b2' ) ) {
00051                         $backend = FileBackendGroup::singleton()->get( $this->getOption( 'b2' ) );
00052                         $this->doPerfTest( $backend );
00053                 }
00054 
00055                 $profiler = Profiler::instance();
00056                 $profiler->setTemplated( true );
00057 
00058                 //NOTE: as of MW1.21, $profiler->logData() is called implicitly by doMaintenance.php.
00059         }
00060 
00061         protected function doPerfTest( FileBackend $backend ) {
00062                 $ops1 = array();
00063                 $ops2 = array();
00064                 $ops3 = array();
00065                 $ops4 = array();
00066                 $ops5 = array();
00067 
00068                 $baseDir = 'mwstore://' . $backend->getName() . '/testing-cont1';
00069                 $backend->prepare( array( 'dir' => $baseDir ) );
00070 
00071                 $dirname = $this->getOption( 'srcdir' );
00072                 $dir = opendir( $dirname );
00073                 if ( !$dir ) {
00074                         return;
00075                 }
00076 
00077                 while ( $dir && ( $file = readdir( $dir ) ) !== false ) {
00078                         if ( $file[0] != '.' ) {
00079                                 $this->output( "Using '$dirname/$file' in operations.\n" );
00080                                 $dst = $baseDir . '/' . wfBaseName( $file );
00081                                 $ops1[] = array( 'op' => 'store',
00082                                         'src' => "$dirname/$file", 'dst' => $dst, 'overwrite' => 1);
00083                                 $ops2[] = array( 'op' => 'copy',
00084                                         'src' => "$dst", 'dst' => "$dst-1", 'overwrite' => 1 );
00085                                 $ops3[] = array( 'op' => 'move',
00086                                         'src' => $dst, 'dst' => "$dst-2", 'overwrite' => 1 );
00087                                 $ops4[] = array( 'op' => 'delete', 'src' => "$dst-1" );
00088                                 $ops5[] = array( 'op' => 'delete', 'src' => "$dst-2" );
00089                         }
00090                         if ( count( $ops1 ) >= $this->getOption( 'maxfiles', 20 ) ) {
00091                                 break; // enough
00092                         }
00093                 }
00094                 closedir( $dir );
00095                 $this->output( "\n" );
00096 
00097                 $method = $this->hasOption( 'quick' ) ? 'doQuickOperations' : 'doOperations';
00098 
00099                 $opts = array( 'force' => 1 );
00100                 if ( $this->hasOption( 'parallelize' ) ) {
00101                         $opts['parallelize'] = ( $this->getOption( 'parallelize' ) === 'true' );
00102                 }
00103 
00104                 $start = microtime( true );
00105                 $status = $backend->$method( $ops1, $opts );
00106                 $e = ( microtime( true ) - $start ) * 1000;
00107                 if ( $status->getErrorsArray() ) {
00108                         print_r( $status->getErrorsArray() );
00109                         exit(0);
00110                 }
00111                 $this->output( $backend->getName() . ": Stored " . count( $ops1 ) . " files in $e ms.\n" );
00112 
00113                 $start = microtime( true );
00114                 $backend->$method( $ops2, $opts );
00115                 $e = ( microtime( true ) - $start ) * 1000;
00116                 if ( $status->getErrorsArray() ) {
00117                         print_r( $status->getErrorsArray() );
00118                         exit(0);
00119                 }
00120                 $this->output( $backend->getName() . ": Copied " . count( $ops2 ) . " files in $e ms.\n" );
00121 
00122                 $start = microtime( true );
00123                 $backend->$method( $ops3, $opts );
00124                 $e = ( microtime( true ) - $start ) * 1000;
00125                 if ( $status->getErrorsArray() ) {
00126                         print_r( $status->getErrorsArray() );
00127                         exit(0);
00128                 }
00129                 $this->output( $backend->getName() . ": Moved " . count( $ops3 ) . " files in $e ms.\n" );
00130 
00131                 $start = microtime( true );
00132                 $backend->$method( $ops4, $opts );
00133                 $e = ( microtime( true ) - $start ) * 1000;
00134                 if ( $status->getErrorsArray() ) {
00135                         print_r( $status->getErrorsArray() );
00136                         exit(0);
00137                 }
00138                 $this->output( $backend->getName() . ": Deleted " . count( $ops4 ) . " files in $e ms.\n" );
00139 
00140                 $start = microtime( true );
00141                 $backend->$method( $ops5, $opts );
00142                 $e = ( microtime( true ) - $start ) * 1000;
00143                 if ( $status->getErrorsArray() ) {
00144                         print_r( $status->getErrorsArray() );
00145                         exit(0);
00146                 }
00147                 $this->output( $backend->getName() . ": Deleted " . count( $ops5 ) . " files in $e ms.\n" );
00148         }
00149 }
00150 
00151 $maintClass = "TestFileOpPerformance";
00152 require_once( RUN_MAINTENANCE_IF_MAIN );