1
0
Fork 0
mirror of synced 2024-10-03 10:46:27 +13:00

Add get worker pool size function

This commit is contained in:
Jake Barnby 2022-11-09 16:19:01 +13:00
parent 958e5424f0
commit e1d80c2b93
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C

View file

@ -1006,6 +1006,26 @@ function getDevice($root): Device
}
}
/**
* Get database connection pool size for worker processes.
*
* @return int
* @throws \Exception
*/
function getWorkerPoolSize(): int
{
$reservedConnections = APP_DATABASE_DEFAULT_POOL_SIZE; // Pool of default size is reserved for the HTTP API
$workerCount = swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6));
$maxConnections = App::getenv('_APP_DB_MAX_CONNECTIONS', 1001);
$workerConnections = $maxConnections - $reservedConnections;
if ($workerCount > $workerConnections) {
throw new \Exception('Worker pool size is too small. Increase the number of allowed database connections or decrease the number of workers.');
}
return (int)($workerConnections / $workerCount);
}
App::setResource('mode', function ($request) {
/** @var Appwrite\Utopia\Request $request */