From d960a949bdf448439354be402cd3ceadcc414cad Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 19 Jun 2018 08:37:23 +0300 Subject: [PATCH] Tune PHP for better performance --- base/PHP5Daemon.php | 8 +++++++- base/PerfOptions.php | 10 +++++++++- conf/php-fpm.conf.in | 2 ++ conf/php.ini | 6 ++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/base/PHP5Daemon.php b/base/PHP5Daemon.php index 4aa7f46..914b32d 100644 --- a/base/PHP5Daemon.php +++ b/base/PHP5Daemon.php @@ -83,9 +83,14 @@ protected function getArguments(): Vector { PerfSettings::BackendPort(), $config ); + $config = str_replace( + "__BACKLOG__", + (string) $this->options->phpFCGIBacklog, + $config + ); $config = str_replace( "__CHILDREN__", - $this->options->serverThreads, + (string) $this->options->phpFCGIChildren, $config ); $config = str_replace( @@ -163,6 +168,7 @@ protected function getEnvironmentVariables(): Map { return Map { 'OSS_PERF_TARGET' => (string) $this->target, 'PHP_FCGI_CHILDREN' => (string) $this->options->phpFCGIChildren, + 'PHP_FCGI_BACKLOG' => (string) $this->options->phpFCGIBacklog, 'PHP_FCGI_MAX_REQUESTS' => '0', }; } diff --git a/base/PerfOptions.php b/base/PerfOptions.php index 897a54e..af9ef95 100644 --- a/base/PerfOptions.php +++ b/base/PerfOptions.php @@ -34,6 +34,7 @@ final class PerfOptions { public array $phpExtraArguments; public int $phpFCGIChildren; + public int $phpFCGIBacklog; public string $siege; public string $nginx; @@ -117,6 +118,7 @@ final class PerfOptions { public ?string $scriptAfterWarmup; public ?string $scriptAfterBenchmark; public string $serverThreads = '100'; + public string $serverBacklog = '256'; public string $clientThreads = '200'; public bool $notBenchmarking = false; @@ -166,6 +168,7 @@ public function __construct(Vector $argv) { 'hhvm-extra-arguments:', 'php-extra-arguments:', 'php-fcgi-children:', + 'php-fcgi-backlog:', 'no-time-limit', 'fetch-resources', 'skip-sanity-check', @@ -314,7 +317,12 @@ public function __construct(Vector $argv) { $this->hhvmExtraArguments = $this->getArray('hhvm-extra-arguments'); $this->phpExtraArguments = $this->getArray('php-extra-arguments'); - $this->phpFCGIChildren = $this->getInt('php-fcgi-children', 100); + $output = []; + exec('nproc', $output); + $numProcessors = (int)($output[0]); + + $this->phpFCGIChildren = $this->getInt('php-fcgi-children', $numProcessors * 2); + $this->phpFCGIBacklog = $this->getInt('php-fcgi-backlog', 256); $this->delayNginxStartup = $this->getFloat('delay-nginx-startup', 0.1); $this->delayPhpStartup = $this->getFloat('delay-php-startup', 1.0); $this->delayProcessLaunch = $this->getFloat('delay-process-launch', 0.0); diff --git a/conf/php-fpm.conf.in b/conf/php-fpm.conf.in index 5f8132f..824a23c 100644 --- a/conf/php-fpm.conf.in +++ b/conf/php-fpm.conf.in @@ -20,6 +20,8 @@ listen = 127.0.0.1:__FASTCGI_PORT__ ; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect. listen.allowed_clients = 127.0.0.1 +listen.backlog = __BACKLOG__ + ; static - a fixed number (pm.max_children) of child processes; pm = static diff --git a/conf/php.ini b/conf/php.ini index 3ca1bfb..ccca5eb 100644 --- a/conf/php.ini +++ b/conf/php.ini @@ -41,3 +41,9 @@ opcache.max_accelerated_files=100000 opcache.max_wasted_percentage=5 opcache.memory_consumption=1024 opcache.consistency_checks=0 + +zend.assertions=-1 +zend.detect_unicode=0 +mysqlnd.collect_statistics=0 +opcache.huge_code_pages=1 +opcache.optimization_level=-1