mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 17:08:45 +00:00
Allow multiprocess for db queue
This commit is contained in:
parent
365630ff39
commit
d238d79e29
5 changed files with 27 additions and 30 deletions
1
.env
1
.env
|
|
@ -5,6 +5,7 @@ _APP_CONSOLE_WHITELIST_ROOT=disabled
|
|||
_APP_CONSOLE_WHITELIST_EMAILS=
|
||||
_APP_CONSOLE_WHITELIST_IPS=
|
||||
_APP_CONNECTIONS_QUEUE_PER_WORKER=enabled
|
||||
_APP_CONNECTIONS_DB_QUEUES=v1-database-0,v1-database-1,v1-database-2
|
||||
_APP_SYSTEM_EMAIL_NAME=Appwrite
|
||||
_APP_SYSTEM_EMAIL_ADDRESS=team@appwrite.io
|
||||
_APP_SYSTEM_SECURITY_EMAIL_ADDRESS=security@appwrite.io
|
||||
|
|
|
|||
|
|
@ -15,33 +15,10 @@ require_once __DIR__ . '/../init.php';
|
|||
Console::title('Database V1 Worker');
|
||||
Console::success(APP_NAME . ' database worker v1 has started' . "\n");
|
||||
|
||||
$table = new Swoole\Table(1);
|
||||
$table->column('workerCount', Swoole\Table::TYPE_INT);
|
||||
$table->create();
|
||||
$table->set('databases', ['workerCount' => 0]);
|
||||
|
||||
$lock = new Swoole\Lock(SWOOLE_MUTEX);
|
||||
|
||||
class DatabaseV1 extends Worker
|
||||
{
|
||||
public function init(): void
|
||||
{
|
||||
global $table, $lock;
|
||||
|
||||
$dbQueues = App::getEnv('_APP_CONNECTIONS_QUEUE_PER_WORKER', 'disabled');
|
||||
|
||||
if ($dbQueues !== 'enabled') {
|
||||
$queue = 'v1-database';
|
||||
} else {
|
||||
$project = new Document($this->args['project']);
|
||||
$queue = $project->getAttribute('database');
|
||||
}
|
||||
|
||||
\putenv('QUEUE=' . $queue);
|
||||
|
||||
$lock->lock();
|
||||
$table->incr('databases', 'workerCount');
|
||||
$lock->unlock();
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
|
|
@ -82,11 +59,6 @@ class DatabaseV1 extends Worker
|
|||
|
||||
public function shutdown(): void
|
||||
{
|
||||
global $table, $lock;
|
||||
|
||||
$lock->lock();
|
||||
$table->decr('databases', 'workerCount');
|
||||
$lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,4 +7,18 @@ else
|
|||
REDIS_BACKEND="redis://${_APP_REDIS_USER}:${_APP_REDIS_PASS}@${_APP_REDIS_HOST}:${_APP_REDIS_PORT}"
|
||||
fi
|
||||
|
||||
INTERVAL=0.1 APP_INCLUDE='/usr/src/code/app/workers/databases.php' php /usr/src/code/vendor/bin/resque -dopcache.preload=opcache.preload=/usr/src/code/app/preload.php
|
||||
queues="${_APP_CONNECTIONS_DB_QUEUES}"
|
||||
if [ -z "${queues}" ]; then
|
||||
queues="v1-databases"
|
||||
fi
|
||||
|
||||
count=1
|
||||
if [ "${_APP_CONNECTIONS_QUEUE_PER_WORKER}" = "enabled" ]; then
|
||||
count=$(echo "${queues}" | tr ',' '\n' | wc -l)
|
||||
fi
|
||||
|
||||
INTERVAL=0.1 \
|
||||
QUEUE="${queues}" \
|
||||
COUNT=${count} \
|
||||
APP_INCLUDE='/usr/src/code/app/workers/databases.php' \
|
||||
php /usr/src/code/vendor/bin/resque -dopcache.preload=opcache.preload=/usr/src/code/app/preload.php
|
||||
|
|
|
|||
|
|
@ -366,6 +366,7 @@ services:
|
|||
- mariadb
|
||||
environment:
|
||||
- _APP_ENV
|
||||
- _APP_CONNECTIONS_QUEUE_PER_WORKER
|
||||
- _APP_CONNECTIONS_DB_QUEUES
|
||||
- _APP_WORKER_PER_CORE
|
||||
- _APP_OPENSSL_KEY_V1
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Appwrite\Event;
|
||||
|
||||
use Resque;
|
||||
use Utopia\App;
|
||||
use Utopia\Database\Document;
|
||||
|
||||
class Database extends Event
|
||||
|
|
@ -14,7 +15,15 @@ class Database extends Event
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(Event::DATABASE_QUEUE_NAME, Event::DATABASE_CLASS_NAME);
|
||||
$dbQueues = App::getEnv('_APP_CONNECTIONS_DB_QUEUES');
|
||||
|
||||
if (empty($dbQueues)) {
|
||||
$queue = Event::DATABASE_QUEUE_NAME;
|
||||
} else {
|
||||
$queue = $this->getProject()->getAttribute('database');
|
||||
}
|
||||
|
||||
parent::__construct($queue, Event::DATABASE_CLASS_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue