69a2a7824b6fd459634f1a7e0cfbac07cfe2805e
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 $initialTime = microtime( true );
25 $wgProfiler = array( 'class' => 'ProfilerSimpleText' );
26 error_reporting( E_ALL
);
28 require_once( dirname( __FILE__
) . '/Maintenance.php' );
31 * Maintenance script to test fileop performance.
33 * @ingroup Maintenance
35 class TestFileOpPerformance
extends Maintenance
{
36 public function __construct() {
37 parent
::__construct();
38 $this->mDescription
= "Test fileop performance";
39 $this->addOption( 'b1', 'Backend 1', true, true );
40 $this->addOption( 'b2', 'Backend 2', false, true );
41 $this->addOption( 'srcdir', 'File source directory', true, true );
42 $this->addOption( 'maxfiles', 'Max files', false, true );
45 public function execute() {
46 $backend = FileBackendGroup
::singleton()->get( $this->getOption( 'b1' ) );
47 $this->doPerfTest( $backend );
49 if ( $this->getOption( 'b2' ) ) {
50 $backend = FileBackendGroup
::singleton()->get( $this->getOption( 'b2' ) );
51 $this->doPerfTest( $backend );
54 $profiler = Profiler
::instance();
55 $profiler->setTemplated( true );
56 $profiler->logData(); // prints
59 protected function doPerfTest( FileBackend
$backend ) {
66 $baseDir = 'mwstore://' . $backend->getName() . '/testing-cont1';
67 $backend->prepare( array( '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[] = array( 'op' => 'store', 'src' => "$dirname/$file", 'dst' => $dst, 'overwrite' => 1);
80 $ops2[] = array( 'op' => 'copy', 'src' => "$dst", 'dst' => "$dst-1", 'overwrite' => 1);
81 $ops3[] = array( 'op' => 'move', 'src' => $dst, 'dst' => "$dst-2", 'overwrite' => 1);
82 $ops4[] = array( 'op' => 'delete', 'src' => "$dst-1", 'overwrite' => 1 );
83 $ops5[] = array( 'op' => 'delete', 'src' => "$dst-2", 'overwrite' => 1 );
85 if ( count( $ops1 ) >= $this->getOption( 'maxfiles', 20 ) ) {
90 $this->output( "\n" );
92 $start = microtime( true );
93 $status = $backend->doOperations( $ops1, array( 'force' => 1 ) );
94 $e = ( microtime( true ) - $start ) * 1000;
95 if ( $status->getErrorsArray() ) {
96 print_r( $status->getErrorsArray() );
99 $this->output( $backend->getName() . ": Stored " . count( $ops1 ) . " files in $e ms.\n" );
101 $start = microtime( true );
102 $backend->doOperations( $ops2, array( 'force' => 1 ) );
103 $e = ( microtime( true ) - $start ) * 1000;
104 if ( $status->getErrorsArray() ) {
105 print_r( $status->getErrorsArray() );
108 $this->output( $backend->getName() . ": Copied " . count( $ops2 ) . " files in $e ms.\n" );
110 $start = microtime( true );
111 $backend->doOperations( $ops3, array( 'force' => 1 ) );
112 $e = ( microtime( true ) - $start ) * 1000;
113 if ( $status->getErrorsArray() ) {
114 print_r( $status->getErrorsArray() );
117 $this->output( $backend->getName() . ": Moved " . count( $ops3 ) . " files in $e ms.\n" );
119 $start = microtime( true );
120 $backend->doOperations( $ops4, array( 'force' => 1 ) );
121 $e = ( microtime( true ) - $start ) * 1000;
122 if ( $status->getErrorsArray() ) {
123 print_r( $status->getErrorsArray() );
126 $this->output( $backend->getName() . ": Deleted " . count( $ops4 ) . " files in $e ms.\n" );
128 $start = microtime( true );
129 $backend->doOperations( $ops5, array( 'force' => 1 ) );
130 $e = ( microtime( true ) - $start ) * 1000;
131 if ( $status->getErrorsArray() ) {
132 print_r( $status->getErrorsArray() );
135 $this->output( $backend->getName() . ": Deleted " . count( $ops5 ) . " files in $e ms.\n" );
139 $maintClass = "TestFileOpPerformance";
140 require_once( RUN_MAINTENANCE_IF_MAIN
);