2005-01-20 07:10:29 +00:00
|
|
|
<?php
|
2005-01-27 23:25:16 +00:00
|
|
|
/**
|
2017-11-01 20:55:24 +00:00
|
|
|
* Benchmark for CDN 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
|
|
|
|
2019-12-18 01:24:42 +00:00
|
|
|
require_once __DIR__ . '/../includes/Benchmarker.php';
|
2005-01-20 07:10:29 +00:00
|
|
|
|
2012-09-04 16:48:17 +00:00
|
|
|
/**
|
2017-11-01 20:55:24 +00:00
|
|
|
* Maintenance script that benchmarks CDN purge.
|
2012-09-04 16:48:17 +00:00
|
|
|
*
|
|
|
|
|
* @ingroup Benchmark
|
|
|
|
|
*/
|
2010-12-31 07:13:40 +00:00
|
|
|
class BenchmarkPurge extends Benchmarker {
|
2009-08-02 19:35:17 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2017-11-01 20:55:24 +00:00
|
|
|
$this->addDescription( 'Benchmark the CDN 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() {
|
2017-11-01 20:55:24 +00:00
|
|
|
global $wgUseCdn, $wgCdnServers;
|
|
|
|
|
|
|
|
|
|
if ( !$wgUseCdn ) {
|
|
|
|
|
$this->error( "CDN purge benchmark doesn't do much without CDN support on." );
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
2017-11-01 20:55:24 +00:00
|
|
|
$this->output( "There are " . count( $wgCdnServers ) . " defined CDN servers:\n" );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $this->hasOption( 'count' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$lengths = [ intval( $this->getOption( 'count' ) ) ];
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$lengths = [ 1, 10, 100 ];
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $lengths as $length ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$urls = $this->randomUrlList( $length );
|
2017-11-01 20:55:24 +00:00
|
|
|
$trial = $this->benchCdn( $urls );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( $trial . "\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-01-20 07:10:29 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
|
|
|
|
/**
|
2019-02-05 19:35:05 +00:00
|
|
|
* Run a bunch of URLs through CdnCacheUpdate::purge()
|
2017-11-01 20:55:24 +00:00
|
|
|
* to benchmark CDN response times.
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param array $urls A bunch of URLs to purge
|
|
|
|
|
* @param int $trials 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
|
|
|
*/
|
2017-11-01 20:55:24 +00:00
|
|
|
private function benchCdn( $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++ ) {
|
2015-12-09 18:05:59 +00:00
|
|
|
CdnCacheUpdate::purge( $urls );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
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 );
|
2014-04-23 18:08:42 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
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.
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param int $length 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 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$list = [];
|
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();
|
|
|
|
|
}
|
2014-04-23 18:08:42 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
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;
|
2014-04-23 18:08:42 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
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
|
|
|
}
|
2014-04-23 18:08:42 +00:00
|
|
|
|
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
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = BenchmarkPurge::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|