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