From e7835112332cf73f4715fdb26e4e4edda3a92691 Mon Sep 17 00:00:00 2001 From: kevand900 Date: Fri, 28 Jul 2017 07:25:04 -0700 Subject: [PATCH] Adding a command line option to specify a remote Siege client. (#83) 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=@, and is to be paried with --i-am-not-benchmarking. --- base/PerfOptions.php | 25 +++++++++++++++++++++++-- base/PerfRunner.php | 5 +++++ base/Siege.php | 23 +++++++++++++++++++++-- base/SiegeStats.php | 4 ++++ 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/base/PerfOptions.php b/base/PerfOptions.php index e39f243..b8c2cb3 100644 --- a/base/PerfOptions.php +++ b/base/PerfOptions.php @@ -127,6 +127,9 @@ final class PerfOptions { private array $args; private Vector $notBenchmarkingArgs = Vector {}; + public ?string $remoteSiege; + public ?string $siegeTmpDir; + public function __construct(Vector $argv) { $def = Vector { 'help', @@ -188,6 +191,7 @@ public function __construct(Vector $argv) { 'db-host:', 'server-threads:', 'client-threads:', + 'remote-siege:', }; $targets = $this->getTargetDefinitions()->keys(); $def->addAll($targets); @@ -333,11 +337,11 @@ public function __construct(Vector $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']; } @@ -351,6 +355,8 @@ public function __construct(Vector $argv) { } $this->srcDir = $this->getNullableString('src-dir'); + + $this->remoteSiege = $this->getNullableString('remote-siege'); } public function validate() { @@ -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 @'); + 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 '. diff --git a/base/PerfRunner.php b/base/PerfRunner.php index ea0c2de..c037212 100644 --- a/base/PerfRunner.php +++ b/base/PerfRunner.php @@ -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(); diff --git a/base/Siege.php b/base/Siege.php index 4e725e1..5b3fa33 100644 --- a/base/Siege.php +++ b/base/Siege.php @@ -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(); } @@ -93,9 +100,15 @@ protected function getArguments(): Vector { $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 { @@ -145,6 +158,12 @@ protected function getArguments(): Vector { ); return $arguments; case RequestModes::BENCHMARK: + if($this->options->remoteSiege) { + $logfile = $this->options->siegeTmpDir . '/' . + basename($this->logfile); + } else { + $logfile = $this->logfile; + } $arguments->addAll( Vector { '-c', @@ -152,7 +171,7 @@ protected function getArguments(): Vector { '-f', $urls_file, '--benchmark', - '--log='.$this->logfile, + '--log='.$logfile, }, ); diff --git a/base/SiegeStats.php b/base/SiegeStats.php index 6c20f53..8e27700 100644 --- a/base/SiegeStats.php +++ b/base/SiegeStats.php @@ -15,6 +15,10 @@ abstract protected function getLogFilePath(): string; public function collectStats(): Map> { $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',