MediaWiki  1.23.6
fileOpPerfTest.php
Go to the documentation of this file.
1 <?php
24 error_reporting( E_ALL );
25 require_once __DIR__ . '/Maintenance.php';
26 
33  public function __construct() {
34  parent::__construct();
35  $this->mDescription = "Test fileop performance";
36  $this->addOption( 'b1', 'Backend 1', true, true );
37  $this->addOption( 'b2', 'Backend 2', false, true );
38  $this->addOption( 'srcdir', 'File source directory', true, true );
39  $this->addOption( 'maxfiles', 'Max files', false, true );
40  $this->addOption( 'quick', 'Avoid operation pre-checks (use doQuickOperations())' );
41  $this->addOption( 'parallelize', '"parallelize" flag for doOperations()', false, true );
42  }
43 
44  public function execute() {
45  Profiler::setInstance( new ProfilerSimpleText( array() ) ); // clear
46 
47  $backend = FileBackendGroup::singleton()->get( $this->getOption( 'b1' ) );
48  $this->doPerfTest( $backend );
49 
50  if ( $this->getOption( 'b2' ) ) {
51  $backend = FileBackendGroup::singleton()->get( $this->getOption( 'b2' ) );
52  $this->doPerfTest( $backend );
53  }
54 
55  Profiler::instance()->setTemplated( true );
56  // NOTE: as of MW1.21, $profiler->logData() is called implicitly by doMaintenance.php.
57  }
58 
59  protected function doPerfTest( FileBackend $backend ) {
60  $ops1 = array();
61  $ops2 = array();
62  $ops3 = array();
63  $ops4 = array();
64  $ops5 = array();
65 
66  $baseDir = 'mwstore://' . $backend->getName() . '/testing-cont1';
67  $backend->prepare( array( 'dir' => $baseDir ) );
68 
69  $dirname = $this->getOption( 'srcdir' );
70  $dir = opendir( $dirname );
71  if ( !$dir ) {
72  return;
73  }
74 
75  while ( $dir && ( $file = readdir( $dir ) ) !== false ) {
76  if ( $file[0] != '.' ) {
77  $this->output( "Using '$dirname/$file' in operations.\n" );
78  $dst = $baseDir . '/' . wfBaseName( $file );
79  $ops1[] = array( 'op' => 'store',
80  'src' => "$dirname/$file", 'dst' => $dst, 'overwrite' => 1 );
81  $ops2[] = array( 'op' => 'copy',
82  'src' => "$dst", 'dst' => "$dst-1", 'overwrite' => 1 );
83  $ops3[] = array( 'op' => 'move',
84  'src' => $dst, 'dst' => "$dst-2", 'overwrite' => 1 );
85  $ops4[] = array( 'op' => 'delete', 'src' => "$dst-1" );
86  $ops5[] = array( 'op' => 'delete', 'src' => "$dst-2" );
87  }
88  if ( count( $ops1 ) >= $this->getOption( 'maxfiles', 20 ) ) {
89  break; // enough
90  }
91  }
92  closedir( $dir );
93  $this->output( "\n" );
94 
95  $method = $this->hasOption( 'quick' ) ? 'doQuickOperations' : 'doOperations';
96 
97  $opts = array( 'force' => 1 );
98  if ( $this->hasOption( 'parallelize' ) ) {
99  $opts['parallelize'] = ( $this->getOption( 'parallelize' ) === 'true' );
100  }
101 
102  $start = microtime( true );
103  $status = $backend->$method( $ops1, $opts );
104  $e = ( microtime( true ) - $start ) * 1000;
105  if ( $status->getErrorsArray() ) {
106  print_r( $status->getErrorsArray() );
107  exit( 0 );
108  }
109  $this->output( $backend->getName() . ": Stored " . count( $ops1 ) . " files in $e ms.\n" );
110 
111  $start = microtime( true );
112  $backend->$method( $ops2, $opts );
113  $e = ( microtime( true ) - $start ) * 1000;
114  if ( $status->getErrorsArray() ) {
115  print_r( $status->getErrorsArray() );
116  exit( 0 );
117  }
118  $this->output( $backend->getName() . ": Copied " . count( $ops2 ) . " files in $e ms.\n" );
119 
120  $start = microtime( true );
121  $backend->$method( $ops3, $opts );
122  $e = ( microtime( true ) - $start ) * 1000;
123  if ( $status->getErrorsArray() ) {
124  print_r( $status->getErrorsArray() );
125  exit( 0 );
126  }
127  $this->output( $backend->getName() . ": Moved " . count( $ops3 ) . " files in $e ms.\n" );
128 
129  $start = microtime( true );
130  $backend->$method( $ops4, $opts );
131  $e = ( microtime( true ) - $start ) * 1000;
132  if ( $status->getErrorsArray() ) {
133  print_r( $status->getErrorsArray() );
134  exit( 0 );
135  }
136  $this->output( $backend->getName() . ": Deleted " . count( $ops4 ) . " files in $e ms.\n" );
137 
138  $start = microtime( true );
139  $backend->$method( $ops5, $opts );
140  $e = ( microtime( true ) - $start ) * 1000;
141  if ( $status->getErrorsArray() ) {
142  print_r( $status->getErrorsArray() );
143  exit( 0 );
144  }
145  $this->output( $backend->getName() . ": Deleted " . count( $ops5 ) . " files in $e ms.\n" );
146  }
147 }
148 
149 $maintClass = "TestFileOpPerformance";
150 require_once RUN_MAINTENANCE_IF_MAIN;
TestFileOpPerformance\__construct
__construct()
Default constructor.
Definition: fileOpPerfTest.php:33
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
FileBackend
Base class for all file backend classes (including multi-write backends).
Definition: FileBackend.php:85
Profiler\instance
static instance()
Singleton.
Definition: Profiler.php:127
FileBackend\getName
getName()
Get the unique backend name.
Definition: FileBackend.php:167
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
wfBaseName
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
Definition: GlobalFunctions.php:3302
TestFileOpPerformance\doPerfTest
doPerfTest(FileBackend $backend)
Definition: fileOpPerfTest.php:59
$maintClass
$maintClass
Definition: fileOpPerfTest.php:149
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
ProfilerSimpleText
The least sophisticated profiler output class possible, view your source! :)
Definition: ProfilerSimpleText.php:34
FileBackendGroup\singleton
static singleton()
Definition: FileBackendGroup.php:43
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
TestFileOpPerformance
Maintenance script to test fileop performance.
Definition: fileOpPerfTest.php:32
Profiler\setInstance
static setInstance(Profiler $p)
Set the profiler to a specific profiler instance.
Definition: Profiler.php:150
FileBackend\prepare
prepare(array $params)
Prepare a storage directory for usage.
Definition: FileBackend.php:754
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
$dir
if(count( $args)==0) $dir
Definition: importImages.php:49
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
$e
if( $useReadline) $e
Definition: eval.php:66
TestFileOpPerformance\execute
execute()
Do the actual work.
Definition: fileOpPerfTest.php:44