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

Commit

Permalink
Add processor affinity setting "--cpu-fraction".
Browse files Browse the repository at this point in the history
  • Loading branch information
mofarrell committed Mar 10, 2017
1 parent ec8f4f5 commit 29961c6
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 3 deletions.
12 changes: 11 additions & 1 deletion base/DatabaseInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ final class DatabaseInstaller {
private ?string $username;
private ?string $password = null;

public function __construct(private PerfOptions $options): void {}
public function __construct(private PerfOptions $options): void {
$this->configureMysqlAffinity();
}

public function getUsername(): ?string {
return $this->username ? $this->username : $this->databaseName;
Expand All @@ -35,6 +37,14 @@ public function setDumpFile(string $dump_file): this {
return $this;
}

public function configureMysqlAffinity(): void {
if ($this->options->cpuBind) {
exec("sudo taskset -acp ".$this->options->helperProcessors." `pgrep mysqld`");
print "You need to restart mysql after the benchmarks to remove the ";
print "processor affinity.\n";
}
}

public function installDatabase(): bool {
$db = $this->databaseName;
$dump = $this->dumpFile;
Expand Down
3 changes: 3 additions & 0 deletions base/HHVMDaemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ protected function getTarget(): PerfTarget {

<<__Override>>
protected function getArguments(): Vector<string> {
if ($this->options->cpuBind) {
$this->cpuRange = $this->options->daemonProcessors;
}
$args = Vector {
'-m',
'server',
Expand Down
3 changes: 3 additions & 0 deletions base/NginxDaemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ protected function getPidFilePath(): string {

<<__Override>>
protected function getArguments(): Vector<string> {
if ($this->options->cpuBind) {
$this->cpuRange = $this->options->helperProcessors;
}
return Vector {
'-c',
$this->getGeneratedConfigFile(),
Expand Down
3 changes: 3 additions & 0 deletions base/PHP5Daemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public function start(): void {
}

protected function getArguments(): Vector<string> {
if ($this->options->cpuBind) {
$this->cpuRange = $this->options->daemonProcessors;
}
if ($this->options->fpm) {
echo 'Creating PHP FPM config';
$path = $this->options->tempDir.'/php-fpm.conf';
Expand Down
16 changes: 16 additions & 0 deletions base/PerfOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ final class PerfOptions {
public ?string $dbUsername;
public ?string $dbPassword;

public bool $cpuBind = false;
public ?string $daemonProcessors;
public ?string $helperProcessors;

public bool $fetchResources = false;
public bool $forceInnodb = false;
public bool $skipSanityCheck = false;
Expand Down Expand Up @@ -146,6 +150,7 @@ public function __construct(Vector<string> $argv) {
'setUpTest:',
'db-username:',
'db-password:',
'cpu-fraction:',
'tearDownTest:',
'i-am-not-benchmarking',
'hhvm-extra-arguments:',
Expand Down Expand Up @@ -255,6 +260,17 @@ public function __construct(Vector<string> $argv) {
$this->proxygen = !$this->getBool('no-proxygen');
$this->applyPatches = $this->getBool('apply-patches');

$fraction = $this->getFloat('cpu-fraction', 1.0);
if ($fraction !== 1.0) {
$this->cpuBind = true;
$output = [];
exec('nproc', $output);
$numProcessors = (int)($output[0]);
$numDaemonProcessors = (int)($numProcessors * $fraction);
$this->helperProcessors = "$numDaemonProcessors-$numProcessors";
$this->daemonProcessors = "0-$numDaemonProcessors";
}

$this->precompile = !$this->getBool('no-repo-auth');
$this->filecache = $this->precompile && !$this->getBool('no-file-cache');
$this->pcreCache = $this->getNullableString('pcre-cache');
Expand Down
6 changes: 6 additions & 0 deletions base/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class Process {
protected ?resource $stdin;
protected ?resource $stdout;
protected ?string $command;
protected ?string $cpuRange = null;
protected bool $suppress_stdout = false;

private static Vector<Process> $processes = Vector {};
Expand Down Expand Up @@ -54,6 +55,11 @@ public function startWorker(
if ($this->suppress_stdout) {
$this->command .= ' >/dev/null';
}

if ($this->cpuRange !== null) {
$this->command = 'taskset -c '.$this->cpuRange.' '.$this->command;
}

$use_pipe = ($outputFileName === null);
$spec =
[
Expand Down
3 changes: 3 additions & 0 deletions base/Siege.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public function getExecutablePath(): string {

<<__Override>>
protected function getArguments(): Vector<string> {
if ($this->options->cpuBind) {
$this->cpuRange = $this->options->helperProcessors;
}
$urls_file = tempnam($this->options->tempDir, 'urls');
$urls = file_get_contents($this->target->getURLsFile());
$urls =
Expand Down
6 changes: 5 additions & 1 deletion batch-run.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
},
"settings": {
"username": "root",
"password": "root"
"password": "root",
"options": [
"cpu-fraction=0.5",
"i-am-not-benchmarking"
]
}
}
7 changes: 7 additions & 0 deletions batch-run.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ function batch_get_single_run(
$argv->addAll($runtime['args']);
$argv[] = '--'.$target['name'];

foreach ($target['settings'] as $name => $value) {
if ($name === 'options') {
foreach ((array)$value as $v) {
$argv[] = '--'.$v;
}
}
}
$options = new PerfOptions($argv);
switch ($runtime['type']) {
case BatchRuntimeType::HHVM:
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
sudo apt-get -y install nginx unzip mysql-server
sudo apt-get -y install nginx unzip mysql-server util-linux coreutils
sudo apt-get -y install autotools-dev
sudo apt-get -y install autoconf
sudo apt-get -y install software-properties-common build-essential
Expand Down

0 comments on commit 29961c6

Please sign in to comment.