1
0
Fork 0
mirror of synced 2024-06-30 04:00:34 +12:00

WIP fix too many connections

This commit is contained in:
Jake Barnby 2022-11-07 23:31:54 +13:00
parent 44ca7d9459
commit a6ffab09df
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
2 changed files with 9 additions and 6 deletions

View file

@ -35,6 +35,9 @@ Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
$realtime = new Realtime();
$dbPool = $register->get('dbPool');
$redisPool = $register->get('redisPool');
/**
* Table for statistics across all workers.
*/
@ -354,15 +357,15 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats,
Console::error('Failed to restart pub/sub...');
});
$server->onOpen(function (int $connection, SwooleRequest $request) use ($server, $register, $stats, &$realtime, $logError) {
$server->onOpen(function (int $connection, SwooleRequest $request) use ($server, $dbPool, $redisPool, $stats, &$realtime, $logError) {
$app = new App('UTC');
$request = new Request($request);
$response = new Response(new SwooleResponse());
/** @var PDO $db */
$db = $register->get('dbPool')->get();
$db = $dbPool->get();
/** @var Redis $redis */
$redis = $register->get('redisPool')->get();
$redis = $redisPool->get();
Console::info("Connection open (user: {$connection})");
@ -477,8 +480,8 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server,
/**
* Put used PDO and Redis Connections back into their pools.
*/
$register->get('dbPool')->put($db);
$register->get('redisPool')->put($redis);
$dbPool->put($db);
$redisPool->put($redis);
}
});

View file

@ -707,7 +707,7 @@ services:
- MYSQL_DATABASE=${_APP_DB_SCHEMA}
- MYSQL_USER=${_APP_DB_USER}
- MYSQL_PASSWORD=${_APP_DB_PASS}
command: 'mysqld --innodb-flush-method=fsync' # add ' --query_cache_size=0' for DB tests
command: 'mysqld --innodb-flush-method=fsync --max_connections=49152' # 128 (CPUs) * 6 (Workers) * 64 (Pool size)
# command: mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bu && mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bu
# smtp: