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

Add Mem target, a very memory intensive variation of MediaWiki #101

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base/PerfOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ private function getTargetDefinitions(
'drupal8-no-cache' => () ==> new Drupal8NoCacheTarget($this),
'mediawiki' => () ==> new MediaWikiTarget($this),
'mediawiki-mlp' => () ==> new MediaWikiMLPTarget($this),
'mediawiki-mem' => () ==> new MediaWikiMemTarget($this),
'laravel4-hello-world' => () ==> new Laravel4Target($this),
'laravel5-hello-world' => () ==> new Laravel5Target($this),
'sugarcrm-login-page' => () ==> new SugarCRMLoginPageTarget($this),
Expand Down
90 changes: 90 additions & 0 deletions targets/mediawiki/MediaWikiMemTarget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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 MediaWikiMemTarget 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__', 'localhost');
$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__.'/mem_mlp.php', $this->getSourceRoot().'/mem_mlp.php');
copy(__DIR__.'/lambdachase.php', $this->getSourceRoot().'/lambdachase.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;
}
}
140 changes: 140 additions & 0 deletions targets/mediawiki/MediaWikiMemTarget.urls
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.php
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.php
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.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=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/mem_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__/mem_mlp.php
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=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Talk:Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=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
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=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.php
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__/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=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.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__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Special:UserLogin
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/mem_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=Main_Page
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=Talk:Main_Page
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=HHVM&action=history
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=Main_Page&action=history
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=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.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=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.php
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=HHVM
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
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.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=Main_Page
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__/lambdachase.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=Main_Page
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=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page&action=edit
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Special:UserLogin
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Special:RecentChanges
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__/lambdachase.php
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=HHVM
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.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__/lambdachase.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=Main_Page&printable=yes
http://__HTTP_HOST__:__HTTP_PORT__/mem_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=Talk:Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/mem_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=Main_Page
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=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.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__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Special:RecentChanges
http://__HTTP_HOST__:__HTTP_PORT__/mem_mlp.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=HHVM
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.php
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/lambdachase.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=Talk:Main_Page
http://__HTTP_HOST__:__HTTP_PORT__/index.php?title=Special:UserLogin
56 changes: 56 additions & 0 deletions targets/mediawiki/lambdachase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?hh // strict
class Lambdas {
const NUM_LAMBDAS = 20000;


public static function getLambdas(): dict<string, mixed> {
$m = dict[];
for ($i = 0; $i < self::NUM_LAMBDAS-1; $i++) {
$key = "lambda".\strval($i);
$next = "lambda".\strval($i+1);
$m[$key] = self::lambda($next);
$m["num".\strval($i)] = vec[$i];
}
$key = "lambda".\strval(self::NUM_LAMBDAS - 1);
$next = "lambda0";
$m[$key] = self::lambda($next);
return $m;
}

public static function lambda(string $s): (function (string): string) {
return function(string $x): string use ($s) { return $s; };
}

}

class LambdaChase {
const CHASE_COUNT = 40000;

public function helloWorld(): string {
return 'Hello, world!';
}

public function go(): int {
$count = 0;
$next_f = "lambda0";
$lambdas = Lambdas::getLambdas();
for ($i = 1; $i < LambdaChase::CHASE_COUNT; ++$i) {
$f = $lambdas[$next_f];
$next_f = $f($next_f);
$f = $lambdas[$next_f];
$next_f = $f($next_f);
$f = $lambdas[$next_f];
$next_f = $f($next_f);
$count += 3;
}
return $count;
}
}

<<__EntryPoint>>
async function main(): Awaitable<void> {
$chase = new LambdaChase();
printf("%s\n", $chase->helloWorld());
printf("%d\n", $chase->go());
exit(0);
}
71 changes: 71 additions & 0 deletions targets/mediawiki/mem_mlp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?hh // strict

ini_set('memory_limit', '1024M');


class MemMLPChase {
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;
$arrayIdx = rand(1, 30);
$arrayName = "big-array-".\strval($arrayIdx);
printf("%s\n",$arrayName);
$bigArray = \apc_fetch($arrayName);
if (!$bigArray) {
$tagName = "array-tag-".\strval($arrayIdx);
$arrayTag = \apc_fetch($tagName);
if ($arrayTag) {
exit(0);
} else {
$backoffTime = 1000 * rand(1, 1000);
usleep($backoffTime);
$arrayTag = \apc_fetch($tagName);
if ($arrayTag) {
exit(0);
}
}
\apc_add($tagName, $arrayName);
$a = [];
for ($i = 0; $i < MemMLPChase::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(MemMLPChase::ARRAY_LENGTH-1)] = 'index0';
\apc_add($arrayName, $bigArray);
}

$chase = new MemMLPChase();
$count = await $chase->mlp(
$bigArray,
$hits,
);
printf("%s\n",$count);
exit(0);
}
4 changes: 2 additions & 2 deletions targets/mediawiki/mlp.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class MLPChase {
$bigArray['index'.\strval(MLPChase::ARRAY_LENGTH-1)] = 'index0';
\apc_add("my-array", $bigArray);
}

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