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

Commit

Permalink
Change --proxygen to still use nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed May 12, 2015
1 parent 0a3a29a commit 423605b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 37 deletions.
16 changes: 3 additions & 13 deletions base/HHVMDaemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

final class HHVMDaemon extends PHPEngine {
private PerfTarget $target;
private int $mainPort;
private int $adminPort;
private string $serverType;

public function __construct(
Expand All @@ -21,15 +19,7 @@ public function __construct(
$this->target = $options->getTarget();
parent::__construct((string) $options->hhvm);

if ($options->proxygen) {
$this->serverType = 'proxygen';
$this->mainPort = PerfSettings::HttpPort();
$this->adminPort = PerfSettings::HttpAdminPort();
} else {
$this->serverType = 'fastcgi';
$this->mainPort = PerfSettings::BackendPort();
$this->adminPort = PerfSettings::BackendAdminPort();
}
$this->serverType = $options->proxygen ? 'proxygen' : 'fastcgi';

$output = [];
$check_command = implode(
Expand Down Expand Up @@ -77,12 +67,12 @@ protected function getTarget(): PerfTarget {
protected function getArguments(): Vector<string> {
$args = Vector {
'-m', 'server',
'-p', (string) $this->mainPort,
'-p', (string) PerfSettings::BackendPort(),
'-v', 'AdminServer.Port='.PerfSettings::BackendAdminPort(),
'-v', 'Server.Type='.$this->serverType,
'-v', 'Server.DefaultDocument=index.php',
'-v', 'Server.SourceRoot='.$this->target->getSourceRoot(),
'-v', 'Eval.Jit=1',
'-v', 'AdminServer.Port='.$this->adminPort,
'-c', OSS_PERFORMANCE_ROOT.'/conf/php.ini',
};
if ($this->options->pcreCache) {
Expand Down
25 changes: 23 additions & 2 deletions base/NginxDaemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,32 @@ public function getPid(): ?int {
protected function getGeneratedConfigFile(): string {
$path = $this->options->tempDir.'/nginx.conf';

if ($this->options->proxygen) {
$proxy_pass = sprintf(
'proxy_pass http://127.0.0.1:%d',
PerfSettings::BackendPort(),
);
$admin_proxy_pass = sprintf(
'proxy_pass http://127.0.0.1:%d',
PerfSettings::BackendAdminPort(),
);
} else {
$proxy_pass = sprintf(
'fastcgi_pass 127.0.0.1:%d',
PerfSettings::BackendPort(),
);
$admin_proxy_pass = sprintf(
'fastcgi_pass 127.0.0.1:%d',
PerfSettings::BackendAdminPort(),
);
}

$substitutions = Map {
'__BACKEND_PORT__' => PerfSettings::BackendPort(),
'__HTTP_PORT__' => PerfSettings::HttpPort(),
'__BACKEND_ADMIN_PORT__' => PerfSettings::BackendAdminPort(),
'__HTTP_ADMIN_PORT__' => PerfSettings::HttpAdminPort(),
'__BACKEND_PORT__' => PerfSettings::BackendPort(),
'__PROXY_PASS__' => $proxy_pass,
'__ADMIN_PROXY_PASS__' => $admin_proxy_pass,
'__NGINX_CONFIG_ROOT__' => OSS_PERFORMANCE_ROOT.'/conf/nginx',
'__NGINX_TEMP_DIR__' => $this->options->tempDir,
'__NGINX_KEEPALIVE_TIMEOUT__' =>
Expand Down
31 changes: 12 additions & 19 deletions base/PerfRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ private static function RunWithOptionsAndEngine(
self::PrintProgress('There is no setUpTest');
}

$nginx = null;
if (!$options->proxygen) {
self::PrintProgress('Starting Nginx');
$nginx = new NginxDaemon($options, $target);
$nginx->start();
Process::sleepSeconds($options->delayNginxStartup);
invariant($nginx->isRunning(), 'Failed to start nginx');
}
self::PrintProgress('Starting Nginx');
$nginx = new NginxDaemon($options, $target);
$nginx->start();
Process::sleepSeconds($options->delayNginxStartup);
invariant($nginx->isRunning(), 'Failed to start nginx');

self::PrintProgress('Starting PHP Engine');
$php_engine->start();
Expand Down Expand Up @@ -126,9 +123,7 @@ private static function RunWithOptionsAndEngine(
}

self::PrintProgress('Clearing nginx access.log');
if ($nginx) {
$nginx->clearAccessLog();
}
$nginx->clearAccessLog();

self::PrintProgress('Starting Siege for benchmark');
$siege = new Siege($options, $target, RequestModes::BENCHMARK);
Expand All @@ -148,14 +143,12 @@ private static function RunWithOptionsAndEngine(
}
}

if ($nginx) {
$nginx_stats = $nginx->collectStats();
foreach ($nginx_stats as $page => $stats) {
if ($combined_stats->containsKey($page)) {
$combined_stats[$page]->setAll($stats);
} else {
$combined_stats[$page] = $stats;
}
$nginx_stats = $nginx->collectStats();
foreach ($nginx_stats as $page => $stats) {
if ($combined_stats->containsKey($page)) {
$combined_stats[$page]->setAll($stats);
} else {
$combined_stats[$page] = $stats;
}
}

Expand Down
8 changes: 6 additions & 2 deletions conf/nginx/nginx.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ http {
return 404;
}

fastcgi_pass 127.0.0.1:__BACKEND_PORT__;
rewrite /index.php / break;
__PROXY_PASS__;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Siege sets Accept-Encoding: gzip. php5 and php-ng ignore it, but
Expand All @@ -69,6 +70,8 @@ http {
# Issue for making HHVM match PHP behavior:
# https://github.com/facebook/hhvm/issues/3744
fastcgi_param HTTP_ACCEPT_ENCODING "";
proxy_set_header Accept-Encoding "";
proxy_set_header Host $host:__BACKEND_PORT__;
include __NGINX_CONFIG_ROOT__/fastcgi_params;
}
}
Expand All @@ -83,7 +86,8 @@ http {
scgi_temp_path __NGINX_TEMP_DIR__/admin-scgi_temp;

location / {
fastcgi_pass 127.0.0.1:__BACKEND_ADMIN_PORT__;
proxy_set_header Host $host;
__ADMIN_PROXY_PASS__;
include __NGINX_CONFIG_ROOT__/fastcgi_params;
}
}
Expand Down
5 changes: 4 additions & 1 deletion targets/wordpress/WordpressTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public function install(): void {
return;
}

$root = 'http://'.gethostname().':'.PerfSettings::HttpPort();
$visible_port = $this->options->proxygen
? PerfSettings::BackendPort()
: PerfSettings::HttpPort();
$root = 'http://'.gethostname().':'.$visible_port;

$conn = mysql_connect('127.0.0.1', 'wp_bench', 'wp_bench');
$db_selected = mysql_select_db('wp_bench', $conn);
Expand Down

0 comments on commit 423605b

Please sign in to comment.