MediaWiki REL1_39
fileOpPerfTest.php
Go to the documentation of this file.
1<?php
25
26require_once __DIR__ . '/Maintenance.php';
27
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Test fileop performance' );
37 $this->addOption( 'b1', 'Backend 1', true, true );
38 $this->addOption( 'b2', 'Backend 2', false, true );
39 $this->addOption( 'srcdir', 'File source directory', true, true );
40 $this->addOption( 'maxfiles', 'Max files', false, true );
41 $this->addOption( 'quick', 'Avoid operation pre-checks (use doQuickOperations())' );
42 $this->addOption( 'parallelize', '"parallelize" flag for doOperations()', false, true );
43 }
44
45 public function execute() {
46 $backendGroup = MediaWikiServices::getInstance()->getFileBackendGroup();
47 $backend = $backendGroup->get( $this->getOption( 'b1' ) );
48 $this->doPerfTest( $backend );
49
50 if ( $this->getOption( 'b2' ) ) {
51 $backend = $backendGroup->get( $this->getOption( 'b2' ) );
52 $this->doPerfTest( $backend );
53 }
54 }
55
56 protected function doPerfTest( FileBackend $backend ) {
57 $ops1 = [];
58 $ops2 = [];
59 $ops3 = [];
60 $ops4 = [];
61 $ops5 = [];
62
63 $baseDir = 'mwstore://' . $backend->getName() . '/testing-cont1';
64 $backend->prepare( [ 'dir' => $baseDir ] );
65
66 $dirname = $this->getOption( 'srcdir' );
67 $dir = opendir( $dirname );
68 if ( !$dir ) {
69 return;
70 }
71
72 while ( ( $file = readdir( $dir ) ) !== false ) {
73 if ( $file[0] != '.' ) {
74 $this->output( "Using '$dirname/$file' in operations.\n" );
75 $dst = $baseDir . '/' . wfBaseName( $file );
76 $ops1[] = [ 'op' => 'store',
77 'src' => "$dirname/$file", 'dst' => $dst, 'overwrite' => true ];
78 $ops2[] = [ 'op' => 'copy',
79 'src' => "$dst", 'dst' => "$dst-1", 'overwrite' => true ];
80 $ops3[] = [ 'op' => 'move',
81 'src' => $dst, 'dst' => "$dst-2", 'overwrite' => true ];
82 $ops4[] = [ 'op' => 'delete', 'src' => "$dst-1" ];
83 $ops5[] = [ 'op' => 'delete', 'src' => "$dst-2" ];
84 }
85 if ( count( $ops1 ) >= $this->getOption( 'maxfiles', 20 ) ) {
86 break;
87 }
88 }
89 closedir( $dir );
90 $this->output( "\n" );
91
92 $method = $this->hasOption( 'quick' ) ? 'doQuickOperations' : 'doOperations';
93
94 $opts = [ 'force' => 1 ];
95 if ( $this->hasOption( 'parallelize' ) ) {
96 $opts['parallelize'] = ( $this->getOption( 'parallelize' ) === 'true' );
97 }
98
99 $start = microtime( true );
100 $status = $backend->$method( $ops1, $opts );
101 $e = ( microtime( true ) - $start ) * 1000;
102 if ( $status->getErrorsArray() ) {
103 print_r( $status->getErrorsArray() );
104 return;
105 }
106 $this->output( $backend->getName() . ": Stored " . count( $ops1 ) . " files in $e ms.\n" );
107
108 $start = microtime( true );
109 $backend->$method( $ops2, $opts );
110 $e = ( microtime( true ) - $start ) * 1000;
111 if ( $status->getErrorsArray() ) {
112 print_r( $status->getErrorsArray() );
113 return;
114 }
115 $this->output( $backend->getName() . ": Copied " . count( $ops2 ) . " files in $e ms.\n" );
116
117 $start = microtime( true );
118 $backend->$method( $ops3, $opts );
119 $e = ( microtime( true ) - $start ) * 1000;
120 if ( $status->getErrorsArray() ) {
121 print_r( $status->getErrorsArray() );
122 return;
123 }
124 $this->output( $backend->getName() . ": Moved " . count( $ops3 ) . " files in $e ms.\n" );
125
126 $start = microtime( true );
127 $backend->$method( $ops4, $opts );
128 $e = ( microtime( true ) - $start ) * 1000;
129 if ( $status->getErrorsArray() ) {
130 print_r( $status->getErrorsArray() );
131 return;
132 }
133 $this->output( $backend->getName() . ": Deleted " . count( $ops4 ) . " files in $e ms.\n" );
134
135 $start = microtime( true );
136 $backend->$method( $ops5, $opts );
137 $e = ( microtime( true ) - $start ) * 1000;
138 if ( $status->getErrorsArray() ) {
139 print_r( $status->getErrorsArray() );
140 return;
141 }
142 $this->output( $backend->getName() . ": Deleted " . count( $ops5 ) . " files in $e ms.\n" );
143 }
144}
145
146$maintClass = FileOpPerfTest::class;
147require_once RUN_MAINTENANCE_IF_MAIN;
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
Base class for all file backend classes (including multi-write backends).
prepare(array $params)
Prepare a storage directory for usage.
getName()
Get the unique backend name.
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.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Service locator for MediaWiki core services.
$maintClass
return true
Definition router.php:92
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42