28require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
40 $this->
addOption(
'b1',
'Backend 1',
true,
true );
41 $this->
addOption(
'b2',
'Backend 2',
false,
true );
42 $this->
addOption(
'srcdir',
'File source directory',
true,
true );
43 $this->
addOption(
'maxfiles',
'Max files',
false,
true );
44 $this->
addOption(
'quick',
'Avoid operation pre-checks (use doQuickOperations())' );
45 $this->
addOption(
'parallelize',
'"parallelize" flag for doOperations()',
false,
true );
50 $backend = $backendGroup->get( $this->
getOption(
'b1' ) );
54 $backend = $backendGroup->get( $this->
getOption(
'b2' ) );
66 $baseDir =
'mwstore://' . $backend->
getName() .
'/testing-cont1';
67 $backend->
prepare( [
'dir' => $baseDir ] );
70 $dir = opendir( $dirname );
76 while ( ( $file = readdir( $dir ) ) !==
false ) {
77 if ( $file[0] !=
'.' ) {
78 $this->
output(
"Using '$dirname/$file' in operations.\n" );
80 $ops1[] = [
'op' =>
'store',
81 'src' =>
"$dirname/$file",
'dst' => $dst,
'overwrite' => true ];
82 $ops2[] = [
'op' =>
'copy',
83 'src' =>
"$dst",
'dst' =>
"$dst-1",
'overwrite' => true ];
84 $ops3[] = [
'op' =>
'move',
85 'src' => $dst,
'dst' =>
"$dst-2",
'overwrite' => true ];
86 $ops4[] = [
'op' =>
'delete',
'src' =>
"$dst-1" ];
87 $ops5[] = [
'op' =>
'delete',
'src' =>
"$dst-2" ];
89 if ( count( $ops1 ) >= $this->
getOption(
'maxfiles', 20 ) ) {
96 $method = $this->
hasOption(
'quick' ) ?
'doQuickOperations' :
'doOperations';
98 $opts = [
'force' => 1 ];
99 if ( $this->
hasOption(
'parallelize' ) ) {
100 $opts[
'parallelize'] = ( $this->
getOption(
'parallelize' ) ===
'true' );
103 $start = microtime(
true );
104 $status = $backend->$method( $ops1, $opts );
105 $e = ( microtime(
true ) - $start ) * 1000;
106 if ( !$status->isGood() ) {
107 $this->
error( $status );
110 $this->
output( $backend->
getName() .
": Stored " . count( $ops1 ) .
" files in $e ms.\n" );
112 $start = microtime(
true );
113 $status = $backend->$method( $ops2, $opts );
114 $e = ( microtime(
true ) - $start ) * 1000;
115 if ( !$status->isGood() ) {
116 $this->
error( $status );
119 $this->
output( $backend->
getName() .
": Copied " . count( $ops2 ) .
" files in $e ms.\n" );
121 $start = microtime(
true );
122 $status = $backend->$method( $ops3, $opts );
123 $e = ( microtime(
true ) - $start ) * 1000;
124 if ( !$status->isGood() ) {
125 $this->
error( $status );
128 $this->
output( $backend->
getName() .
": Moved " . count( $ops3 ) .
" files in $e ms.\n" );
130 $start = microtime(
true );
131 $status = $backend->$method( $ops4, $opts );
132 $e = ( microtime(
true ) - $start ) * 1000;
133 if ( !$status->isGood() ) {
134 $this->
error( $status );
137 $this->
output( $backend->
getName() .
": Deleted " . count( $ops4 ) .
" files in $e ms.\n" );
139 $start = microtime(
true );
140 $status = $backend->$method( $ops5, $opts );
141 $e = ( microtime(
true ) - $start ) * 1000;
142 if ( !$status->isGood() ) {
143 $this->
error( $status );
146 $this->
output( $backend->
getName() .
": Deleted " . count( $ops5 ) .
" files in $e ms.\n" );
152require_once RUN_MAINTENANCE_IF_MAIN;
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
Maintenance script to test fileop performance.
__construct()
Default constructor.
doPerfTest(FileBackend $backend)
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.