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 $wgProfiler = array( 'class' => 'ProfilerSimpleText' );
25 error_reporting( E_ALL
);
27 require_once __DIR__
. '/Maintenance.php';
30 * Maintenance script to test fileop performance.
32 * @ingroup Maintenance
34 class TestFileOpPerformance
extends Maintenance
{
35 public function __construct() {
36 parent
::__construct();
37 $this->mDescription
= "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 );
46 public function execute() {
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 = Profiler
::instance();
56 $profiler->setTemplated( true );
58 //NOTE: as of MW1.21, $profiler->logData() is called implicitly by doMaintenance.php.
61 protected function doPerfTest( FileBackend
$backend ) {
68 $baseDir = 'mwstore://' . $backend->getName() . '/testing-cont1';
69 $backend->prepare( array( 'dir' => $baseDir ) );
71 $dirname = $this->getOption( 'srcdir' );
72 $dir = opendir( $dirname );
77 while ( $dir && ( $file = readdir( $dir ) ) !== false ) {
78 if ( $file[0] != '.' ) {
79 $this->output( "Using '$dirname/$file' in operations.\n" );
80 $dst = $baseDir . '/' . wfBaseName( $file );
81 $ops1[] = array( 'op' => 'store',
82 'src' => "$dirname/$file", 'dst' => $dst, 'overwrite' => 1 );
83 $ops2[] = array( 'op' => 'copy',
84 'src' => "$dst", 'dst' => "$dst-1", 'overwrite' => 1 );
85 $ops3[] = array( 'op' => 'move',
86 'src' => $dst, 'dst' => "$dst-2", 'overwrite' => 1 );
87 $ops4[] = array( 'op' => 'delete', 'src' => "$dst-1" );
88 $ops5[] = array( 'op' => 'delete', 'src' => "$dst-2" );
90 if ( count( $ops1 ) >= $this->getOption( 'maxfiles', 20 ) ) {
95 $this->output( "\n" );
97 $method = $this->hasOption( 'quick' ) ?
'doQuickOperations' : 'doOperations';
99 $opts = array( 'force' => 1 );
100 if ( $this->hasOption( 'parallelize' ) ) {
101 $opts['parallelize'] = ( $this->getOption( 'parallelize' ) === 'true' );
104 $start = microtime( true );
105 $status = $backend->$method( $ops1, $opts );
106 $e = ( microtime( true ) - $start ) * 1000;
107 if ( $status->getErrorsArray() ) {
108 print_r( $status->getErrorsArray() );
111 $this->output( $backend->getName() . ": Stored " . count( $ops1 ) . " files in $e ms.\n" );
113 $start = microtime( true );
114 $backend->$method( $ops2, $opts );
115 $e = ( microtime( true ) - $start ) * 1000;
116 if ( $status->getErrorsArray() ) {
117 print_r( $status->getErrorsArray() );
120 $this->output( $backend->getName() . ": Copied " . count( $ops2 ) . " files in $e ms.\n" );
122 $start = microtime( true );
123 $backend->$method( $ops3, $opts );
124 $e = ( microtime( true ) - $start ) * 1000;
125 if ( $status->getErrorsArray() ) {
126 print_r( $status->getErrorsArray() );
129 $this->output( $backend->getName() . ": Moved " . count( $ops3 ) . " files in $e ms.\n" );
131 $start = microtime( true );
132 $backend->$method( $ops4, $opts );
133 $e = ( microtime( true ) - $start ) * 1000;
134 if ( $status->getErrorsArray() ) {
135 print_r( $status->getErrorsArray() );
138 $this->output( $backend->getName() . ": Deleted " . count( $ops4 ) . " files in $e ms.\n" );
140 $start = microtime( true );
141 $backend->$method( $ops5, $opts );
142 $e = ( microtime( true ) - $start ) * 1000;
143 if ( $status->getErrorsArray() ) {
144 print_r( $status->getErrorsArray() );
147 $this->output( $backend->getName() . ": Deleted " . count( $ops5 ) . " files in $e ms.\n" );
151 $maintClass = "TestFileOpPerformance";
152 require_once RUN_MAINTENANCE_IF_MAIN
;