Skip to content

Commit

Permalink
optimize swoole (TechEmpower#9261)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman authored Sep 12, 2024
1 parent 8222e5d commit 64398bc
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion frameworks/PHP/swoole/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static function init(string $driver): void
->withUsername('benchmarkdbuser')
->withPassword('benchmarkdbpass');

self::$pool = new PDOPool($config, 128);
self::$pool = new PDOPool($config, intval(1400 / swoole_cpu_num()));
self::$driver = $driver;
}

Expand Down
1 change: 1 addition & 0 deletions frameworks/PHP/swoole/php.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.validate_timestamps=0
Expand Down
1 change: 1 addition & 0 deletions frameworks/PHP/swoole/swoole-async-mysql.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM ubuntu:24.04

ENV SWOOLE_VERSION 5.1.4
ENV ENABLE_COROUTINE 1
ENV CPU_MULTIPLES 1
ENV DATABASE_DRIVER mysql

ARG DEBIAN_FRONTEND=noninteractive
Expand Down
1 change: 1 addition & 0 deletions frameworks/PHP/swoole/swoole-async-postgres.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM ubuntu:24.04

ENV SWOOLE_VERSION 5.1.4
ENV ENABLE_COROUTINE 1
ENV CPU_MULTIPLES 1
ENV DATABASE_DRIVER pgsql

ARG DEBIAN_FRONTEND=noninteractive
Expand Down
6 changes: 2 additions & 4 deletions frameworks/PHP/swoole/swoole-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@
$enableCoroutine = getenv('ENABLE_COROUTINE') == 1;
$connection = $enableCoroutine ? Connections::class : Connection::class;

$server = new Server('0.0.0.0', 8080);
$setting = [
'worker_num' => swoole_cpu_num() * 4,
'worker_num' => swoole_cpu_num() * ((int) getenv('CPU_MULTIPLES')),
'log_file' => '/dev/null',
'enable_coroutine' => $enableCoroutine,
'enable_reuse_port' => true
];

if ($enableCoroutine) {
$setting['hook_flags'] = SWOOLE_HOOK_ALL;
$setting['worker_num'] = swoole_cpu_num();
}

$server = new Server('0.0.0.0', 8080);
$server->set($setting);


$server->on('workerStart', function () use ($connection) {
$connection::init(getenv('DATABASE_DRIVER'));
});
Expand Down
1 change: 1 addition & 0 deletions frameworks/PHP/swoole/swoole-sync-mysql.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM ubuntu:24.04

ENV SWOOLE_VERSION 5.1.4
ENV ENABLE_COROUTINE 0
ENV CPU_MULTIPLES 1
ENV DATABASE_DRIVER mysql

ARG DEBIAN_FRONTEND=noninteractive
Expand Down
3 changes: 2 additions & 1 deletion frameworks/PHP/swoole/swoole-sync-postgres.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM ubuntu:24.04

ENV SWOOLE_VERSION 5.1.4
ENV ENABLE_COROUTINE 0
ENV CPU_MULTIPLES 4
ENV DATABASE_DRIVER pgsql

ARG DEBIAN_FRONTEND=noninteractive
Expand All @@ -15,7 +16,7 @@ RUN apt update -yqq > /dev/null \
&& cd /tmp/swoole-src-${SWOOLE_VERSION} \
&& phpize > /dev/null \
&& ./configure > /dev/null \
&& make -j2 > /dev/null \
&& make -j8 > /dev/null \
&& make install > /dev/null \
&& echo "extension=swoole.so" > /etc/php/8.3/cli/conf.d/50-swoole.ini

Expand Down

0 comments on commit 64398bc

Please sign in to comment.