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

Adding a command line parameter --run-multiple which will automatical… #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions base/NginxDaemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function start(): void {
);
}

public function stop(): void {
parent::stop();
}

public function clearAccessLog(): void {
$log = $this->options->tempDir.'/access.log';
invariant(
Expand Down
5 changes: 4 additions & 1 deletion base/PerfOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ final class PerfOptions {

public ?string $remoteSiege;
public ?string $siegeTmpDir;

public bool $runMultiple;
public function __construct(Vector<string> $argv) {
$def = Vector {
'help',
Expand Down Expand Up @@ -192,6 +192,7 @@ public function __construct(Vector<string> $argv) {
'server-threads:',
'client-threads:',
'remote-siege:',
'run-multiple',
};
$targets = $this->getTargetDefinitions()->keys();
$def->addAll($targets);
Expand Down Expand Up @@ -357,6 +358,8 @@ public function __construct(Vector<string> $argv) {
$this->srcDir = $this->getNullableString('src-dir');

$this->remoteSiege = $this->getNullableString('remote-siege');

$this->runMultiple = $this->getBool('run-multiple');
}

public function validate() {
Expand Down
50 changes: 48 additions & 2 deletions base/PerfRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,53 @@
final class PerfRunner {
public static function RunWithArgv(Vector<string> $argv): PerfResult {
$options = new PerfOptions($argv);
return self::RunWithOptions($options);
$data = self::RunWithOptions($options);

if ($options->runMultiple) {
print json_encode($data, JSON_PRETTY_PRINT)."\n";
$numRuns = PerfSettings::NumRuns();
$dataArr = Vector{$data};
for ($i = 0; $i<$numRuns-1; $i++) {
self::PrintProgress('Sleeping before run: ' . ($i+2) . '/' . $numRuns);
sleep(PerfSettings::SleepTime());
self::PrintProgress('Starting run: ' . ($i+2) . '/' . $numRuns);
$data = self::RunWithOptions($options);
$dataArr->add($data);
self::PrintProgress('Results for run: ' . ($i+2) . '/' . $numRuns);
print json_encode($data, JSON_PRETTY_PRINT)."\n";
}
$data = self::PostProcess($dataArr, $data);
self::PrintProgress('Average of ' . ($numRuns-2) . ':');
}

return $data;
}

public static function PerfSort($a, $b) {
if ($a['Combined']['Siege RPS'] == $b['Combined']['Siege RPS']) return 0;
return ($a['Combined']['Siege RPS'] < $b['Combined']['Siege RPS']) ? -1 : 1;
}

public static function PostProcess(Vector<PerfResult> $dataArr, PerfResult $data): PerfResult {
usort($dataArr, "self::PerfSort");
$dataArr->removeKey(0);
$dataArr->pop();
$keys = $dataArr->firstValue();

if ($keys) {
$keys = $keys->at('Combined')->toKeysArray();

for ($i=0; $i<count($keys)-1; $i++) {
$avg = 0;

for ($j=0; $j<$dataArr->count(); $j++) {
$avg += $dataArr->at($j)['Combined']->at($keys[$i]);
}
$avg = ($avg / $dataArr->count());
$data['Combined'][$keys[$i]] = $avg;
}
}
return $data;
}

public static function RunWithOptions(PerfOptions $options): PerfResult {
Expand Down Expand Up @@ -236,7 +282,7 @@ private static function RunWithOptionsAndEngine(
} else {
self::PrintProgress('There is no tearDownTest');
}

$nginx->stop();
return $combined_stats;
}

Expand Down
8 changes: 8 additions & 0 deletions base/PerfSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@ public static function BackendPort(): int {
public static function BackendAdminPort(): int {
return 8093;
}

public static function SleepTime(): int {
return 180;
}

public static function NumRuns(): int {
return 7;
}
}