Save executor stats into cache

This commit is contained in:
Matej Bačo
2022-10-14 11:30:42 +00:00
parent 5807523488
commit 73b29e9005
6 changed files with 55 additions and 9 deletions
+3
View File
@@ -10,6 +10,9 @@ class Random extends Adapter
{
$executors = $this->getExecutors();
$executor = $executors[\array_rand($executors)] ?? null;
\var_dump($executor);
return $executor ?? null;
}
}
+1 -1
View File
@@ -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
{
+43
View File
@@ -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;
}
}