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