Add smarter traefik load balancing with health check
This commit is contained in:
parent
db792999c1
commit
2ab6156db4
2
.env
2
.env
|
@ -1,6 +1,6 @@
|
|||
_APP_ENV=development
|
||||
_APP_LOCALE=en
|
||||
_APP_WORKER_PER_CORE=6
|
||||
_APP_WORKER_PER_CORE=1
|
||||
_APP_CONSOLE_WHITELIST_ROOT=disabled
|
||||
_APP_CONSOLE_WHITELIST_EMAILS=
|
||||
_APP_CONSOLE_WHITELIST_IPS=
|
||||
|
|
|
@ -51,8 +51,16 @@ App::get('/v1/health/version')
|
|||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_HEALTH_VERSION)
|
||||
->inject('http')
|
||||
->inject('response')
|
||||
->action(function (Response $response) {
|
||||
->action(function (mixed $http, Response $response) {
|
||||
$stats = $http->stats();
|
||||
\var_dump(\gethostname() . ': ' . $stats['idle_worker_num'] . '/' . $stats['worker_num']);
|
||||
|
||||
if(($stats['idle_worker_num'] ?? 0) <= 1) {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Can not process more requests at the moment.');
|
||||
}
|
||||
|
||||
$response->dynamic(new Document([ 'version' => APP_VERSION_STABLE ]), Response::MODEL_HEALTH_VERSION);
|
||||
});
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ App::get('/versions')
|
|||
->label('scope', 'public')
|
||||
->inject('response')
|
||||
->action(function (Response $response) {
|
||||
\sleep(60);
|
||||
$platforms = Config::getParam('platforms');
|
||||
|
||||
$versions = [
|
||||
|
|
|
@ -327,4 +327,11 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo
|
|||
}
|
||||
});
|
||||
|
||||
$register->set('http', function () use ($http) {
|
||||
return $http;
|
||||
});
|
||||
App::setResource('http', function ($register) {
|
||||
return $register->get('http');
|
||||
}, ['register']);
|
||||
|
||||
$http->start();
|
||||
|
|
|
@ -44,7 +44,9 @@ services:
|
|||
- appwrite
|
||||
|
||||
appwrite:
|
||||
container_name: appwrite
|
||||
deploy:
|
||||
mode: replicated
|
||||
replicas: 3
|
||||
<<: *x-logging
|
||||
image: appwrite-dev
|
||||
build:
|
||||
|
@ -53,8 +55,6 @@ services:
|
|||
DEBUG: false
|
||||
TESTING: true
|
||||
VERSION: dev
|
||||
ports:
|
||||
- 9501:80
|
||||
networks:
|
||||
- appwrite
|
||||
labels:
|
||||
|
@ -62,6 +62,9 @@ services:
|
|||
- "traefik.constraint-label-stack=appwrite"
|
||||
- "traefik.docker.network=appwrite"
|
||||
- "traefik.http.services.appwrite_api.loadbalancer.server.port=80"
|
||||
- "traefik.http.services.appwrite_api.loadbalancer.healthcheck.path=/v1/health/version"
|
||||
- "traefik.http.services.appwrite_api.loadbalancer.healthcheck.interval=3s"
|
||||
- "traefik.http.services.appwrite_api.loadbalancer.healthcheck.timeout=2s"
|
||||
#http
|
||||
- traefik.http.routers.appwrite_api_http.entrypoints=appwrite_web
|
||||
- traefik.http.routers.appwrite_api_http.rule=PathPrefix(`/`)
|
||||
|
|
Loading…
Reference in a new issue