2023-09-30 19:41:50 -06:00
|
|
|
import time
|
2023-09-28 18:40:24 -06:00
|
|
|
from threading import Thread
|
|
|
|
|
2023-09-30 19:41:50 -06:00
|
|
|
from llm_server.cluster.backend import test_backend
|
2023-09-29 00:09:44 -06:00
|
|
|
from llm_server.cluster.cluster_config import cluster_config
|
|
|
|
from llm_server.cluster.stores import redis_running_models
|
2023-09-28 18:40:24 -06:00
|
|
|
|
|
|
|
|
|
|
|
def cluster_worker():
|
2023-09-30 19:41:50 -06:00
|
|
|
counter = 0
|
2023-09-28 18:40:24 -06:00
|
|
|
while True:
|
2023-09-30 19:41:50 -06:00
|
|
|
test_prompt = False
|
|
|
|
if counter % 4 == 0:
|
|
|
|
# Only send a test prompt every 120 seconds.
|
|
|
|
test_prompt = True
|
2023-09-28 18:40:24 -06:00
|
|
|
threads = []
|
|
|
|
for n, v in cluster_config.all().items():
|
2023-09-30 19:41:50 -06:00
|
|
|
thread = Thread(target=check_backend, args=(n, v, test_prompt))
|
2023-09-28 18:40:24 -06:00
|
|
|
thread.start()
|
|
|
|
threads.append(thread)
|
|
|
|
for thread in threads:
|
|
|
|
thread.join()
|
2023-09-30 19:41:50 -06:00
|
|
|
time.sleep(15)
|
|
|
|
counter += 1
|
2023-09-28 18:40:24 -06:00
|
|
|
|
|
|
|
|
2023-09-30 19:41:50 -06:00
|
|
|
def check_backend(n, v, test_prompt):
|
|
|
|
online, backend_info = test_backend(v['backend_url'], test_prompt=test_prompt)
|
|
|
|
# purge_backend_from_running_models(n)
|
2023-09-29 00:09:44 -06:00
|
|
|
if online:
|
2023-09-30 19:41:50 -06:00
|
|
|
running_model = backend_info['model']
|
|
|
|
for k, v in backend_info.items():
|
|
|
|
cluster_config.set_backend_value(n, k, v)
|
|
|
|
redis_running_models.sadd(running_model, n)
|
|
|
|
else:
|
|
|
|
for model in redis_running_models.keys():
|
|
|
|
redis_running_models.srem(model, n)
|
|
|
|
|
|
|
|
# redis_running_models.srem(backend_info['model'], n)
|
|
|
|
# backend_cycler_store.lrem(backend_info['model'], 1, n)
|
|
|
|
|
2023-09-28 18:40:24 -06:00
|
|
|
cluster_config.set_backend_value(n, 'online', online)
|