1
0
Fork 0
mirror of synced 2024-10-01 01:37:56 +13:00

Merge pull request #4748 from appwrite/fix-db-pool-sharing

Fix: db pool sharing
This commit is contained in:
Christy Jacob 2022-11-22 13:32:08 +05:30 committed by GitHub
commit 259f868cc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 12 deletions

3
.env
View file

@ -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

View file

@ -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);

14
composer.lock generated
View file

@ -2356,16 +2356,16 @@
}, },
{ {
"name": "utopia-php/pools", "name": "utopia-php/pools",
"version": "0.4.1", "version": "0.4.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/pools.git", "url": "https://github.com/utopia-php/pools.git",
"reference": "c8f96a33e7fbf58c1145eb6cf0f2c00cbe319979" "reference": "d2870ab74b31b7f4027799f082e85122154f8bed"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/pools/zipball/c8f96a33e7fbf58c1145eb6cf0f2c00cbe319979", "url": "https://api.github.com/repos/utopia-php/pools/zipball/d2870ab74b31b7f4027799f082e85122154f8bed",
"reference": "c8f96a33e7fbf58c1145eb6cf0f2c00cbe319979", "reference": "d2870ab74b31b7f4027799f082e85122154f8bed",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2401,9 +2401,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/utopia-php/pools/issues", "issues": "https://github.com/utopia-php/pools/issues",
"source": "https://github.com/utopia-php/pools/tree/0.4.1" "source": "https://github.com/utopia-php/pools/tree/0.4.2"
}, },
"time": "2022-11-15T08:55:16+00:00" "time": "2022-11-22T07:55:45+00:00"
}, },
{ {
"name": "utopia-php/preloader", "name": "utopia-php/preloader",
@ -5403,5 +5403,5 @@
"platform-overrides": { "platform-overrides": {
"php": "8.0" "php": "8.0"
}, },
"plugin-api-version": "2.1.0" "plugin-api-version": "2.3.0"
} }

View file

@ -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