Skip to content

Commit 64398bc

Browse files
optimize swoole (#9261)
1 parent 8222e5d commit 64398bc

File tree

7 files changed

+9
-6
lines changed

7 files changed

+9
-6
lines changed

frameworks/PHP/swoole/database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static function init(string $driver): void
144144
->withUsername('benchmarkdbuser')
145145
->withPassword('benchmarkdbpass');
146146

147-
self::$pool = new PDOPool($config, 128);
147+
self::$pool = new PDOPool($config, intval(1400 / swoole_cpu_num()));
148148
self::$driver = $driver;
149149
}
150150

frameworks/PHP/swoole/php.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
zend_extension=opcache.so
12
opcache.enable=1
23
opcache.enable_cli=1
34
opcache.validate_timestamps=0

frameworks/PHP/swoole/swoole-async-mysql.dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM ubuntu:24.04
22

33
ENV SWOOLE_VERSION 5.1.4
44
ENV ENABLE_COROUTINE 1
5+
ENV CPU_MULTIPLES 1
56
ENV DATABASE_DRIVER mysql
67

78
ARG DEBIAN_FRONTEND=noninteractive

frameworks/PHP/swoole/swoole-async-postgres.dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM ubuntu:24.04
22

33
ENV SWOOLE_VERSION 5.1.4
44
ENV ENABLE_COROUTINE 1
5+
ENV CPU_MULTIPLES 1
56
ENV DATABASE_DRIVER pgsql
67

78
ARG DEBIAN_FRONTEND=noninteractive

frameworks/PHP/swoole/swoole-server.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@
88
$enableCoroutine = getenv('ENABLE_COROUTINE') == 1;
99
$connection = $enableCoroutine ? Connections::class : Connection::class;
1010

11-
$server = new Server('0.0.0.0', 8080);
1211
$setting = [
13-
'worker_num' => swoole_cpu_num() * 4,
12+
'worker_num' => swoole_cpu_num() * ((int) getenv('CPU_MULTIPLES')),
1413
'log_file' => '/dev/null',
1514
'enable_coroutine' => $enableCoroutine,
1615
'enable_reuse_port' => true
1716
];
1817

1918
if ($enableCoroutine) {
2019
$setting['hook_flags'] = SWOOLE_HOOK_ALL;
21-
$setting['worker_num'] = swoole_cpu_num();
2220
}
2321

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

26-
2725
$server->on('workerStart', function () use ($connection) {
2826
$connection::init(getenv('DATABASE_DRIVER'));
2927
});

frameworks/PHP/swoole/swoole-sync-mysql.dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM ubuntu:24.04
22

33
ENV SWOOLE_VERSION 5.1.4
44
ENV ENABLE_COROUTINE 0
5+
ENV CPU_MULTIPLES 1
56
ENV DATABASE_DRIVER mysql
67

78
ARG DEBIAN_FRONTEND=noninteractive

frameworks/PHP/swoole/swoole-sync-postgres.dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM ubuntu:24.04
22

33
ENV SWOOLE_VERSION 5.1.4
44
ENV ENABLE_COROUTINE 0
5+
ENV CPU_MULTIPLES 4
56
ENV DATABASE_DRIVER pgsql
67

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

0 commit comments

Comments
 (0)