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