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

Commit

Permalink
Adding a command line option to specify a remote Siege client. (#83)
Browse files Browse the repository at this point in the history
Please note you must set up privileged SSH connection between the Server and Client.
It is also necessary to modify IP tables to allow INPUT and OUTPUT between Server and Client.
Remote Client is specified by --remote-siege=<user>@<host>, and is to be paried with --i-am-not-benchmarking.
  • Loading branch information
kevand900 authored and mofarrell committed Jul 28, 2017
1 parent 9b1a334 commit e783511
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
25 changes: 23 additions & 2 deletions base/PerfOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ final class PerfOptions {
private array $args;
private Vector<string> $notBenchmarkingArgs = Vector {};

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

public function __construct(Vector<string> $argv) {
$def = Vector {
'help',
Expand Down Expand Up @@ -188,6 +191,7 @@ public function __construct(Vector<string> $argv) {
'db-host:',
'server-threads:',
'client-threads:',
'remote-siege:',
};
$targets = $this->getTargetDefinitions()->keys();
$def->addAll($targets);
Expand Down Expand Up @@ -333,11 +337,11 @@ public function __construct(Vector<string> $argv) {
$this->dbHost = $host;
}

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

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

Expand All @@ -351,6 +355,8 @@ public function __construct(Vector<string> $argv) {
}

$this->srcDir = $this->getNullableString('src-dir');

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

public function validate() {
Expand All @@ -376,6 +382,21 @@ public function validate() {
exit(1);
}
}
if ($this->remoteSiege) {
if (preg_match('*@*',$this->remoteSiege) === 0){
invariant_violation('%s',
'Please provide Siege remote host in the form of <user>@<host>');
exit(1);
}
$ret = 0;
$output = "";
$this->siegeTmpDir = exec('ssh ' .
$this->remoteSiege . ' mktemp -d ', $output, $ret);
if ($ret) {
invariant_violation('%s',
'Invalid ssh credentials: ' . $this->remoteSiege);
}
}
if ($this->php5 === null && $this->hhvm === null) {
invariant_violation(
'Either --php5=/path/to/php-cgi or --php=/path/to/php-fpm or '.
Expand Down
5 changes: 5 additions & 0 deletions base/PerfRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ private static function RunWithOptionsAndEngine(
}

self::PrintProgress('Collecting results');
if ($options->remoteSiege) {
exec((' scp ' .
$options->remoteSiege . ':' . $options->siegeTmpDir . '/* '.
$options->tempDir));
}

$combined_stats = Map {};
$siege_stats = $siege->collectStats();
Expand Down
23 changes: 21 additions & 2 deletions base/Siege.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public function start(): void {

<<__Override>>
public function getExecutablePath(): string {
if ($this->options->remoteSiege) {
if ($this->options->noTimeLimit) {
return 'ssh ' . $this->options->remoteSiege . ' ' .
parent::getExecutablePath();
}
return 'ssh ' . $this->options->remoteSiege . ' \'timeout\'';
}
if ($this->options->noTimeLimit) {
return parent::getExecutablePath();
}
Expand All @@ -93,9 +100,15 @@ protected function getArguments(): Vector<string> {
$urls =
str_replace('__HTTP_PORT__', (string) PerfSettings::HttpPort(), $urls);
// Siege doesn't support ipv6
$urls = str_replace('__HTTP_HOST__', '127.0.0.1', $urls);
$urls = str_replace('__HTTP_HOST__', gethostname(), $urls);
file_put_contents($urls_file, $urls);

if ($this->options->remoteSiege) {
exec('scp ' . $urls_file . ' ' .
$this->options->remoteSiege . ':' . $this->options->siegeTmpDir);
$urls_file = $this->options->siegeTmpDir . '/' . basename($urls_file);
}

$arguments = Vector {};
if (!$this->options->noTimeLimit) {
$arguments = Vector {
Expand Down Expand Up @@ -145,14 +158,20 @@ protected function getArguments(): Vector<string> {
);
return $arguments;
case RequestModes::BENCHMARK:
if($this->options->remoteSiege) {
$logfile = $this->options->siegeTmpDir . '/' .
basename($this->logfile);
} else {
$logfile = $this->logfile;
}
$arguments->addAll(
Vector {
'-c',
$this->options->clientThreads,
'-f',
$urls_file,
'--benchmark',
'--log='.$this->logfile,
'--log='.$logfile,
},
);

Expand Down
4 changes: 4 additions & 0 deletions base/SiegeStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ abstract protected function getLogFilePath(): string;
public function collectStats(): Map<string, Map<string, num>> {
$log_lines =
explode("\n", trim(file_get_contents($this->getLogFilePath())));
if (count($log_lines) > 1) {
// Remove possible header line
array_splice($log_lines, 0, 1);
}
invariant(
count($log_lines) === 1,
'Expected 1 line in siege log file, got %d',
Expand Down

0 comments on commit e783511

Please sign in to comment.