2005-01-20 07:10:29 +00:00
|
|
|
<?php
|
2005-01-27 23:25:16 +00:00
|
|
|
/**
|
2012-09-04 16:48:17 +00:00
|
|
|
* Benchmark for Squid purge.
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-09-05 13:15:48 +00:00
|
|
|
* @file
|
2012-02-08 16:49:53 +00:00
|
|
|
* @ingroup Benchmark
|
2005-01-27 23:25:16 +00:00
|
|
|
*/
|
2005-01-20 07:10:29 +00:00
|
|
|
|
2012-08-27 19:03:15 +00:00
|
|
|
require_once( __DIR__ . '/Benchmarker.php' );
|
2005-01-20 07:10:29 +00:00
|
|
|
|
2012-09-04 16:48:17 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that benchmarks Squid purge.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Benchmark
|
|
|
|
|
*/
|
2010-12-31 07:13:40 +00:00
|
|
|
class BenchmarkPurge extends Benchmarker {
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->mDescription = "Benchmark the Squid purge functions.";
|
2005-01-20 07:10:29 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2010-07-24 20:01:50 +00:00
|
|
|
global $wgUseSquid, $wgSquidServers;
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( !$wgUseSquid ) {
|
2010-11-11 12:37:22 +00:00
|
|
|
$this->error( "Squid purge benchmark doesn't do much without squid support on.", true );
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
|
|
|
|
$this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $this->hasOption( 'count' ) ) {
|
|
|
|
|
$lengths = array( intval( $this->getOption( 'count' ) ) );
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
|
|
|
|
$lengths = array( 1, 10, 100 );
|
|
|
|
|
}
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $lengths as $length ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$urls = $this->randomUrlList( $length );
|
|
|
|
|
$trial = $this->benchSquid( $urls );
|
|
|
|
|
$this->output( $trial . "\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-01-20 07:10:29 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
|
|
|
|
/**
|
2009-08-02 19:35:17 +00:00
|
|
|
* Run a bunch of URLs through SquidUpdate::purge()
|
|
|
|
|
* to benchmark Squid response times.
|
|
|
|
|
* @param $urls array A bunch of URLs to purge
|
|
|
|
|
* @param $trials int How many times to run the test?
|
2011-10-18 17:31:54 +00:00
|
|
|
* @return string
|
2009-08-02 19:35:17 +00:00
|
|
|
*/
|
|
|
|
|
private function benchSquid( $urls, $trials = 1 ) {
|
2012-09-06 17:47:17 +00:00
|
|
|
$start = microtime( true );
|
2010-05-22 16:50:39 +00:00
|
|
|
for ( $i = 0; $i < $trials; $i++ ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
SquidUpdate::purge( $urls );
|
|
|
|
|
}
|
2012-09-06 17:47:17 +00:00
|
|
|
$delta = microtime( true ) - $start;
|
2009-08-02 19:35:17 +00:00
|
|
|
$pertrial = $delta / $trials;
|
|
|
|
|
$pertitle = $pertrial / count( $urls );
|
|
|
|
|
return sprintf( "%4d titles in %6.2fms (%6.2fms each)",
|
|
|
|
|
count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 );
|
2009-06-24 02:02:37 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
|
|
|
|
/**
|
2009-08-02 19:35:17 +00:00
|
|
|
* Get an array of randomUrl()'s.
|
|
|
|
|
* @param $length int How many urls to add to the array
|
2011-10-18 17:31:54 +00:00
|
|
|
* @return array
|
2009-08-02 19:35:17 +00:00
|
|
|
*/
|
|
|
|
|
private function randomUrlList( $length ) {
|
|
|
|
|
$list = array();
|
2010-05-22 16:50:39 +00:00
|
|
|
for ( $i = 0; $i < $length; $i++ ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$list[] = $this->randomUrl();
|
|
|
|
|
}
|
|
|
|
|
return $list;
|
2005-01-22 01:25:53 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
|
|
|
|
/**
|
2009-08-02 19:35:17 +00:00
|
|
|
* Return a random URL of the wiki. Not necessarily an actual title in the
|
2010-12-04 03:20:14 +00:00
|
|
|
* database, but at least a URL that looks like one.
|
2011-10-18 17:31:54 +00:00
|
|
|
* @return string
|
2009-08-02 19:35:17 +00:00
|
|
|
*/
|
|
|
|
|
private function randomUrl() {
|
|
|
|
|
global $wgServer, $wgArticlePath;
|
|
|
|
|
return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath );
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a random title string (not necessarily a Title object).
|
2009-08-02 19:35:17 +00:00
|
|
|
* For use with randomUrl().
|
2011-10-18 17:31:54 +00:00
|
|
|
* @return string
|
2009-08-02 19:35:17 +00:00
|
|
|
*/
|
|
|
|
|
private function randomTitle() {
|
|
|
|
|
$str = '';
|
|
|
|
|
$length = mt_rand( 1, 20 );
|
2010-05-22 16:50:39 +00:00
|
|
|
for ( $i = 0; $i < $length; $i++ ) {
|
|
|
|
|
$str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
return ucfirst( $str );
|
2005-01-20 07:10:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
|
|
|
|
|
$maintClass = "BenchmarkPurge";
|
2011-01-13 22:58:55 +00:00
|
|
|
require_once( RUN_MAINTENANCE_IF_MAIN );
|