3 * Test for fileop performance.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup Maintenance
24 error_reporting( E_ALL
);
25 require_once __DIR__
. '/Maintenance.php';
28 * Maintenance script to test fileop performance.
30 * @ingroup Maintenance
32 class TestFileOpPerformance
extends Maintenance
{
33 public function __construct() {
34 parent
::__construct();
35 $this->addDescription( '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 );
44 public function execute() {
45 Profiler
::setInstance( new ProfilerSimpleText( [] ) ); // clear
47 $backend = FileBackendGroup
::singleton()->get( $this->getOption( 'b1' ) );
48 $this->doPerfTest( $backend );
50 if ( $this->getOption( 'b2' ) ) {
51 $backend = FileBackendGroup
::singleton()->get( $this->getOption( 'b2' ) );
52 $this->doPerfTest( $backend );
55 Profiler
::instance()->setTemplated( true );
56 // NOTE: as of MW1.21, $profiler->logData() is called implicitly by doMaintenance.php.
59 protected function doPerfTest( FileBackend
$backend ) {
66 $baseDir = 'mwstore://' . $backend->getName() . '/testing-cont1';
67 $backend->prepare( [ 'dir' => $baseDir ] );
69 $dirname = $this->getOption( 'srcdir' );
70 $dir = opendir( $dirname );
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[] = [ 'op' => 'store',
80 'src' => "$dirname/$file", 'dst' => $dst, 'overwrite' => 1 ];
81 $ops2[] = [ 'op' => 'copy',
82 'src' => "$dst", 'dst' => "$dst-1", 'overwrite' => 1 ];
83 $ops3[] = [ 'op' => 'move',
84 'src' => $dst, 'dst' => "$dst-2", 'overwrite' => 1 ];
85 $ops4[] = [ 'op' => 'delete', 'src' => "$dst-1" ];
86 $ops5[] = [ 'op' => 'delete', 'src' => "$dst-2" ];
88 if ( count( $ops1 ) >= $this->getOption( 'maxfiles', 20 ) ) {
93 $this->output( "\n" );
95 $method = $this->hasOption( 'quick' ) ?
'doQuickOperations' : 'doOperations';
97 $opts = [ 'force' => 1 ];
98 if ( $this->hasOption( 'parallelize' ) ) {
99 $opts['parallelize'] = ( $this->getOption( 'parallelize' ) === 'true' );
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() );
109 $this->output( $backend->getName() . ": Stored " . count( $ops1 ) . " files in $e ms.\n" );
111 $start = microtime( true );
112 $backend->$method( $ops2, $opts );
113 $e = ( microtime( true ) - $start ) * 1000;
114 if ( $status->getErrorsArray() ) {
115 print_r( $status->getErrorsArray() );
118 $this->output( $backend->getName() . ": Copied " . count( $ops2 ) . " files in $e ms.\n" );
120 $start = microtime( true );
121 $backend->$method( $ops3, $opts );
122 $e = ( microtime( true ) - $start ) * 1000;
123 if ( $status->getErrorsArray() ) {
124 print_r( $status->getErrorsArray() );
127 $this->output( $backend->getName() . ": Moved " . count( $ops3 ) . " files in $e ms.\n" );
129 $start = microtime( true );
130 $backend->$method( $ops4, $opts );
131 $e = ( microtime( true ) - $start ) * 1000;
132 if ( $status->getErrorsArray() ) {
133 print_r( $status->getErrorsArray() );
136 $this->output( $backend->getName() . ": Deleted " . count( $ops4 ) . " files in $e ms.\n" );
138 $start = microtime( true );
139 $backend->$method( $ops5, $opts );
140 $e = ( microtime( true ) - $start ) * 1000;
141 if ( $status->getErrorsArray() ) {
142 print_r( $status->getErrorsArray() );
145 $this->output( $backend->getName() . ": Deleted " . count( $ops5 ) . " files in $e ms.\n" );
149 $maintClass = "TestFileOpPerformance";
150 require_once RUN_MAINTENANCE_IF_MAIN
;