Skip to content

Commit

Permalink
chore: 优化docker环境下的启动速度,增加webman进程自动重启来释放内存
Browse files Browse the repository at this point in the history
  • Loading branch information
xboard committed May 14, 2024
1 parent fa6dfc6 commit 227f50b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
20 changes: 18 additions & 2 deletions .docker/etc/supervisor/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ logfile=/dev/null
logfile_maxbytes=0
pidfile=/tmp/supervisord.pid

[unix_http_server]
file=/run/supervisord.sock
chmod=0700

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[program:chown]
directory=/www
command=sh -c "chown -R www:www /www && chmod -R 775 /www"
autostart=true
autorestart=false
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:nginx]
command=nginx -g 'daemon off;'
user=root
Expand Down Expand Up @@ -51,7 +68,7 @@ stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autostart=true
autorestart=true
startretries=3
startretries=10

[program:xboard-queue]
command=php artisan horizon
Expand All @@ -64,4 +81,3 @@ stderr_logfile_maxbytes=0
autostart=true
autorestart=true
startretries=10
numprocs=1
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ RUN composer install --optimize-autoloader --no-cache --no-dev \
&& chown -R www:www /www \
&& chmod -R 775 /www

CMD chown -R www:www /www ; chmod -R 775 /www ; /usr/bin/supervisord --nodaemon -c /etc/supervisor/supervisord.conf
CMD /usr/bin/supervisord --nodaemon -c /etc/supervisor/supervisord.conf
12 changes: 9 additions & 3 deletions webman.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Adapterman\Adapterman;
use Workerman\Worker;

Adapterman::init();

$http_worker = new Worker('http://127.0.0.1:7010');
$http_worker->count = getenv('WEBMAN_WORKERS') ?: (swoole_cpu_num() ?: 1);
$http_worker->name = 'AdapterMan';
$http_worker = new Worker('http://127.0.0.1:7010');
$http_worker->count = getenv('WEBMAN_WORKERS') ?: max(swoole_cpu_num(), 2);
$http_worker->name = 'AdapterMan';

$http_worker->onWorkerStart = static function () {
//init();
Expand All @@ -17,7 +18,12 @@

$http_worker->onMessage = static function ($connection, $request) {

static $request_count;

$connection->send(run());
if (++$request_count > 10000) {
Worker::stopAll();
}
};

Worker::runAll();

0 comments on commit 227f50b

Please sign in to comment.