mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Save executor stats into cache
This commit is contained in:
+2
-2
@@ -665,7 +665,7 @@ App::get('/v1/health')
|
||||
$functionsUsage[$containerUsage['name']] = $containerUsage['cpu'];
|
||||
}
|
||||
} catch(\Exception $err) {
|
||||
// TODO: Handle better
|
||||
// TODO: @Meldiron Handle better
|
||||
\var_dump($err);
|
||||
} finally {
|
||||
$orchestrationPool->put($orchestration);
|
||||
@@ -805,7 +805,7 @@ $http->on('start', function ($http) {
|
||||
|
||||
foreach ($orphans as $runtime) {
|
||||
go(function () use ($runtime, $orchestrationPool) {
|
||||
// TODO: Only remove containers prefixed with this executor name
|
||||
// TODO: @Meldiron Only remove containers prefixed with this executor name
|
||||
|
||||
try {
|
||||
$orchestration = $orchestrationPool->get();
|
||||
|
||||
@@ -47,7 +47,7 @@ function markOffline(Cache $cache, string $executorId, string $error, bool $forc
|
||||
{
|
||||
$data = $cache->load('executors-' . $executorId, 60 * 60 * 24 * 30 * 3); // 3 months
|
||||
|
||||
$cache->save('executors-' . $executorId, ['status' => 'offline']);
|
||||
$cache->save('executors-' . $executorId, ['status' => 'offline', 'stats' => []]);
|
||||
|
||||
if (!$data || $data['status'] === 'online' || $forceShowError) {
|
||||
Console::warning('Executor "' . $executorId . '" went down! Message:');
|
||||
@@ -55,11 +55,11 @@ function markOffline(Cache $cache, string $executorId, string $error, bool $forc
|
||||
}
|
||||
}
|
||||
|
||||
function markOnline(cache $cache, string $executorId, bool $forceShowError = false)
|
||||
function markOnline(cache $cache, string $executorId, bool $forceShowError = false, mixed $stats = [])
|
||||
{
|
||||
$data = $cache->load('executors-' . $executorId, 60 * 60 * 24 * 30 * 3); // 3 months
|
||||
|
||||
$cache->save('executors-' . $executorId, ['status' => 'online']);
|
||||
$cache->save('executors-' . $executorId, ['status' => 'online', 'stats' => $stats]);
|
||||
|
||||
if (!$data || $data['status'] === 'offline' || $forceShowError) {
|
||||
Console::success('Executor "' . $executorId . '" went online.');
|
||||
@@ -92,14 +92,14 @@ function fetchExecutorsState(RedisPool $redisPool, bool $forceShowError = false)
|
||||
'x-appwrite-executor-key: ' . App::getEnv('_APP_EXECUTOR_SECRET', '')
|
||||
]);
|
||||
|
||||
$executorResponse = \curl_exec($ch); // TODO: Use to save usage stats
|
||||
$executorResponse = \curl_exec($ch);
|
||||
$statusCode = \curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = \curl_error($ch);
|
||||
|
||||
\curl_close($ch);
|
||||
|
||||
if ($statusCode === 200) {
|
||||
markOnline($cache, $id, $forceShowError);
|
||||
markOnline($cache, $id, $forceShowError, \json_decode($executorResponse, true));
|
||||
} else {
|
||||
$message = 'Code: ' . $statusCode . ' with response "' . $executorResponse . '" and error error: ' . $error;
|
||||
markOffline($cache, $id, $message, $forceShowError);
|
||||
|
||||
Generated
+1
-1
@@ -5401,5 +5401,5 @@
|
||||
"platform-overrides": {
|
||||
"php": "8.0"
|
||||
},
|
||||
"plugin-api-version": "2.2.0"
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ class Random extends Adapter
|
||||
{
|
||||
$executors = $this->getExecutors();
|
||||
$executor = $executors[\array_rand($executors)] ?? null;
|
||||
|
||||
\var_dump($executor);
|
||||
|
||||
return $executor ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use FunctionsProxy\Adapter;
|
||||
|
||||
class RoundRobin extends Adapter
|
||||
{
|
||||
private $currentIndex = 0; // TODO: Put into redis to share across proxies
|
||||
private $currentIndex = 0; // TODO: @Meldiron Put into redis to share across proxies
|
||||
|
||||
public function getNextExecutor(): array
|
||||
{
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace FunctionsProxy\Adapter;
|
||||
|
||||
use FunctionsProxy\Adapter;
|
||||
|
||||
class UsageBased extends Adapter
|
||||
{
|
||||
public function getNextExecutor(): array
|
||||
{
|
||||
$executors = $this->getExecutors();
|
||||
|
||||
/*
|
||||
appwrite-functions-proxy | array(3) {
|
||||
appwrite-functions-proxy | ["id"]=>
|
||||
appwrite-functions-proxy | string(4) "exc2"
|
||||
appwrite-functions-proxy | ["hostname"]=>
|
||||
appwrite-functions-proxy | string(18) "appwrite-executor2"
|
||||
appwrite-functions-proxy | ["state"]=>
|
||||
appwrite-functions-proxy | array(2) {
|
||||
appwrite-functions-proxy | ["status"]=>
|
||||
appwrite-functions-proxy | string(6) "online"
|
||||
appwrite-functions-proxy | ["stats"]=>
|
||||
appwrite-functions-proxy | array(3) {
|
||||
appwrite-functions-proxy | ["status"]=>
|
||||
appwrite-functions-proxy | string(4) "pass"
|
||||
appwrite-functions-proxy | ["hostUsage"]=>
|
||||
appwrite-functions-proxy | float(0.348125)
|
||||
appwrite-functions-proxy | ["functionsUsage"]=>
|
||||
appwrite-functions-proxy | array(0) {
|
||||
appwrite-functions-proxy | }
|
||||
appwrite-functions-proxy | }
|
||||
appwrite-functions-proxy | }
|
||||
appwrite-functions-proxy | }
|
||||
*/
|
||||
|
||||
// TODO: @Meldiron Proper functionality
|
||||
// TODO: @Meldiron Use this adapter and test it
|
||||
|
||||
$executor = $executors[\array_rand($executors)] ?? null;
|
||||
return $executor ?? null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user