Fix pool sharing logic
This commit is contained in:
parent
12b2deda11
commit
f055adc05f
3 changed files with 14 additions and 5 deletions
3
.env
3
.env
|
@ -24,7 +24,8 @@ _APP_DB_SCHEMA=appwrite
|
||||||
_APP_DB_USER=user
|
_APP_DB_USER=user
|
||||||
_APP_DB_PASS=password
|
_APP_DB_PASS=password
|
||||||
_APP_DB_ROOT_PASS=rootsecretpassword
|
_APP_DB_ROOT_PASS=rootsecretpassword
|
||||||
_APP_CONNECTIONS_MAX=251
|
_APP_CONNECTIONS_MAX=151
|
||||||
|
_APP_POOL_CLIENTS=14
|
||||||
_APP_CONNECTIONS_DB_PROJECT=db_fra1_02=mariadb://user:password@mariadb:3306/appwrite
|
_APP_CONNECTIONS_DB_PROJECT=db_fra1_02=mariadb://user:password@mariadb:3306/appwrite
|
||||||
_APP_CONNECTIONS_DB_CONSOLE=db_fra1_01=mariadb://user:password@mariadb:3306/appwrite
|
_APP_CONNECTIONS_DB_CONSOLE=db_fra1_01=mariadb://user:password@mariadb:3306/appwrite
|
||||||
_APP_CONNECTIONS_CACHE=redis_fra1_01=redis://redis:6379
|
_APP_CONNECTIONS_CACHE=redis_fra1_01=redis://redis:6379
|
||||||
|
|
12
app/init.php
12
app/init.php
|
@ -552,10 +552,16 @@ $register->set('pools', function () {
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$instances = 3; // REST, Realtime, CLI
|
$maxConnections = App::getenv('_APP_CONNECTIONS_MAX', 151);
|
||||||
|
$instanceConnections = $maxConnections / App::getenv('_APP_POOL_CLIENTS', 14);
|
||||||
|
|
||||||
|
$multiprocessing = App::getenv('_APP_SERVER_MULTIPROCESS', 'disabled') === 'enabled';
|
||||||
|
|
||||||
|
if($multiprocessing) {
|
||||||
$workerCount = swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6));
|
$workerCount = swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6));
|
||||||
$maxConnections = App::getenv('_APP_CONNECTIONS_MAX', 251);
|
} else {
|
||||||
$instanceConnections = $maxConnections / $instances;
|
$workerCount = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if ($workerCount > $instanceConnections) {
|
if ($workerCount > $instanceConnections) {
|
||||||
throw new \Exception('Pool size is too small. Increase the number of allowed database connections or decrease the number of workers.', 500);
|
throw new \Exception('Pool size is too small. Increase the number of allowed database connections or decrease the number of workers.', 500);
|
||||||
|
|
|
@ -105,6 +105,7 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
- _APP_WORKER_PER_CORE
|
- _APP_WORKER_PER_CORE
|
||||||
|
- _APP_SERVER_MULTIPROCESS=enabled
|
||||||
- _APP_LOCALE
|
- _APP_LOCALE
|
||||||
- _APP_CONSOLE_WHITELIST_ROOT
|
- _APP_CONSOLE_WHITELIST_ROOT
|
||||||
- _APP_CONSOLE_WHITELIST_EMAILS
|
- _APP_CONSOLE_WHITELIST_EMAILS
|
||||||
|
@ -204,6 +205,7 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
- _APP_WORKER_PER_CORE
|
- _APP_WORKER_PER_CORE
|
||||||
|
- _APP_SERVER_MULTIPROCESS=enabled
|
||||||
- _APP_OPTIONS_ABUSE
|
- _APP_OPTIONS_ABUSE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_DB_HOST
|
- _APP_DB_HOST
|
||||||
|
|
Loading…
Reference in a new issue