Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Add MLP target, a memory intensive variation of MediaWiki
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorfox committed Jan 15, 2020
1 parent 917a47f commit 9ca1867
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 3 deletions.
3 changes: 2 additions & 1 deletion base/PerfOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public function __construct(Vector<string> $argv) {
}

if (array_key_exists('client-threads', $o)) {
$this->clientThreads = $this->args['client-threads'];
$this->clientThreads = $this->args['client-threads'];
}

if ($argTempDir === null) {
Expand Down Expand Up @@ -564,6 +564,7 @@ private function getTargetDefinitions(
'drupal8-page-cache' => () ==> new Drupal8PageCacheTarget($this),
'drupal8-no-cache' => () ==> new Drupal8NoCacheTarget($this),
'mediawiki' => () ==> new MediaWikiTarget($this),
'mediawiki-mlp' => () ==> new MediaWikiMLPTarget($this),
'laravel4-hello-world' => () ==> new Laravel4Target($this),
'laravel5-hello-world' => () ==> new Laravel5Target($this),
'sugarcrm-login-page' => () ==> new SugarCRMLoginPageTarget($this),
Expand Down
4 changes: 2 additions & 2 deletions conf/nginx/nginx.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# This file was created on: __DATE__

worker_processes 5;
worker_processes auto;
error_log __NGINX_TEMP_DIR__/nginx-error.log;
pid __NGINX_PID_FILE__;

Expand All @@ -21,7 +21,7 @@ http {
default_type application/octet-stream;

log_format main '$status $body_bytes_sent $request_time "$request"';

types_hash_max_size 4096;
types_hash_bucket_size 64;

Expand Down
89 changes: 89 additions & 0 deletions targets/mediawiki/MediaWikiMLPTarget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?hh
/*
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

final class MediaWikiMLPTarget extends PerfTarget {

const MEDIAWIKI_VERSION = 'mediawiki-1.28.0';

public function __construct(private PerfOptions $options) {}

protected function getSanityCheckString(): string {
return 'Obama';
}

private function replaceInFile(string $fileName, string $search, string $replace) {
$file = $this->getSourceRoot().'/'.$fileName;
$file_contents = file_get_contents($file);
$file_contents = str_replace($search, $replace, $file_contents);
file_put_contents($file, $file_contents);
}

public function install(): void {
$src_dir = $this->options->srcDir;
if ($src_dir) {
Utils::CopyDirContents($src_dir, $this->getSourceRoot());
} else {
Utils::ExtractTar(
__DIR__.'/'.self::MEDIAWIKI_VERSION.'.tar.gz',
$this->options->tempDir,
);
}
(new DatabaseInstaller($this->options))
->setDatabaseName('mw_bench')
->setDumpFile(__DIR__.'/mw_bench.sql.gz')
->installDatabase();

// Put it inside the source root so that if we're generating PHP files and
// we're in repo-auth mode, the generated files end up in the repo
$cache_dir = $this->getSourceRoot().'/mw-cache';
mkdir($cache_dir);
copy(__DIR__.'/LocalSettings.php', $this->getSourceRoot().'/LocalSettings.php');

$this->replaceInFile('LocalSettings.php', '__DB_HOST__', $this->options->dbHost);

file_put_contents(
$this->getSourceRoot().'/LocalSettings.php',
'$wgCacheDirectory="'.$cache_dir.'";'."\n",
FILE_APPEND,
);
if ($this->options->useMemcached) {
copy(__DIR__.'/Memcached.php', $this->getSourceRoot().'/Memcached.php');
$this->replaceInFile('Memcached.php', '__MEMCACHED_HOST__', '127.0.0.1');
$this->replaceInFile('Memcached.php', '__MEMCACHED_PORT__', (string) $this->options->memcachedPort);
file_put_contents(
$this->getSourceRoot().'/LocalSettings.php',
'require_once "'.$this->getSourceRoot().'/Memcached.php";'."\n",
FILE_APPEND,
);
}
copy(__DIR__.'/mlp.php', $this->getSourceRoot().'/mlp.php');
}

<<__Override>>
public function postInstall(): void {
Utils::RunCommand(
Vector {
PHP_BINARY,
$this->getSourceRoot().'/maintenance/rebuildLocalisationCache.php',
'--lang=en',
},
);
}

<<__Override>>
public function getSourceRoot(): string {
return $this->options->tempDir.'/'.self::MEDIAWIKI_VERSION;
}

<<__Override>>
public function supportsMemcached(): bool {
return true;
}
}
24 changes: 24 additions & 0 deletions targets/mediawiki/MediaWikiMLPTarget.urls
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=HHVM
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page&printable=yes
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=HHVM
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page&printable=yes
http://__HTTP_HOST__:__HTTP_PORT__/mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Special:UserLogin
http://__HTTP_HOST__:__HTTP_PORT__/mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Special:RecentChanges
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Special:UserLogin
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page&action=history
http://__HTTP_HOST__:__HTTP_PORT__/mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=HHVM
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Talk:Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Talk:Main_Page&action=edit
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page&action=edit
http://__HTTP_HOST__:__HTTP_PORT__/mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=HHVM&action=history
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page&action=edit
8 changes: 8 additions & 0 deletions targets/mediawiki/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@
$wgSessionCacheType = CACHE_MEMCACHED;
# Turn this option back on if we use memcached
$wgUseDatabaseMessages = true;

$wgSessionsInObjectCache = true; # optional
$wgParserCacheType = CACHE_MEMCACHED; # optional
$wgMessageCacheType = CACHE_MEMCACHED; # optional
$wgLanguageConverterCacheType = CACHE_MEMCACHED;
$wgEnableSidebarCache = true;
$wgMiserMode = true;
$wgDisableCounter = true;
52 changes: 52 additions & 0 deletions targets/mediawiki/mlp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?hh // strict

class MLPChase {
const ARRAY_LENGTH = 1 << 22;

async public function mlp(array $bigArray, int $hits): Awaitable<string> {
$val1 = 'index1';
$val2 = 'index2';
$val3 = 'index3';
$val4 = 'index4';

$hits_per_lane = $hits/5;
for ($i = 0; $i < $hits_per_lane; $i++) {
$val1 = $bigArray[$val1];
$val2 = $bigArray[$val2];
$val3 = $bigArray[$val3];
$val4 = $bigArray[$val4];

}
return $val1.$val2.$val3.$val4;
}

}


<<__EntryPoint>>
async function main(): Awaitable<void> {
$hits = 1 * 4 * 5 * 6 * 7 * 8 * 9 * 6;
$bigArray = \apc_fetch("my-array");
if (!$bigArray) {
$a = [];
for ($i = 0; $i < MLPChase::ARRAY_LENGTH-1; $i++) {
$i_next = $i+1;
$a['index'.\strval($i)] = 'index'.\strval($i_next);
}
$keys = \array_keys($a);
\shuffle(&$keys);
foreach ($keys as $key) {
$bigArray[$key] = $a[$key];
}
$bigArray['index'.\strval(MLPChase::ARRAY_LENGTH-1)] = 'index0';
\apc_add("my-array", $bigArray);
}

$chase = new MLPChase();
$count = await $chase->mlp(
$bigArray,
$hits,
);
printf("%s\n",$count);
exit(0);
}

0 comments on commit 9ca1867

Please sign in to comment.