chore: 迁移服务器前同步本地修改
This commit is contained in:
@@ -15,13 +15,7 @@
|
||||
import time
|
||||
import asyncio
|
||||
from collections import OrderedDict
|
||||
from kilostar.utils.ray_compat import actor_class, _STANDALONE
|
||||
from kilostar.utils.ray_hook import ray_actor_hook
|
||||
|
||||
if _STANDALONE:
|
||||
from asyncio import Queue
|
||||
else:
|
||||
from ray.util.queue import Queue
|
||||
from asyncio import Queue
|
||||
from kilostar.worker_individual.base_individual import BaseIndividual
|
||||
from kilostar.worker_individual.skill_individual import SkillIndividual
|
||||
from kilostar.worker_individual.ordinary_individual import OrdinaryIndividual
|
||||
@@ -31,15 +25,14 @@ from kilostar.worker_individual.special_individual import SpecialIndividual
|
||||
from kilostar.utils.logger import get_logger
|
||||
|
||||
|
||||
@actor_class
|
||||
class WorkerCluster:
|
||||
"""
|
||||
工作集群 Actor:管理和调度所有的 worker_individual
|
||||
设计理念:按需加载,内存 LRU 淘汰,避免 Actor 爆炸
|
||||
工作集群:管理和调度所有的 worker_individual
|
||||
设计理念:按需加载,内存 LRU 淘汰,避免实例爆炸
|
||||
|
||||
分布式模式下每种 node_type 对应一个独立实例,Ray 根据自定义资源
|
||||
``kilostar_node_cpu`` / ``kilostar_node_core`` / ``kilostar_node_gpu``
|
||||
将 Actor 调度到声明了对应资源的节点上。
|
||||
``submit_task`` 是对外的稳定执行边界——未来若要把重型 worker(如 vLLM 本地
|
||||
推理)拆到独立进程/机器上,只需在这个边界后面换一个 executor 实现,上层不感知。
|
||||
``node_type`` 字段暂时保留,供未来按算力亲和性路由使用。
|
||||
"""
|
||||
|
||||
def __init__(self, max_capacity: int = 200, num_runners: int = 10, node_type: str = "cpu"):
|
||||
@@ -70,11 +63,8 @@ class WorkerCluster:
|
||||
|
||||
from kilostar.core.global_state_machine.gsm_snapshot import fetch_snapshot
|
||||
|
||||
global_state_machine = ray_actor_hook(
|
||||
"global_state_machine"
|
||||
).global_state_machine
|
||||
# 走快照读,避开 GSM actor RPC:高频唤醒路径不再是单 actor 瓶颈
|
||||
snapshot = await fetch_snapshot(gsm_actor=global_state_machine)
|
||||
# 走快照读:高频唤醒路径直接读进程内缓存快照
|
||||
snapshot = await fetch_snapshot()
|
||||
agent_config = snapshot.individuals.get(agent_id)
|
||||
|
||||
if not agent_config:
|
||||
@@ -104,7 +94,7 @@ class WorkerCluster:
|
||||
if self.task_queue is None:
|
||||
await asyncio.sleep(0.1)
|
||||
continue
|
||||
task = await self.task_queue.get() if _STANDALONE else await self.task_queue.get_async()
|
||||
task = await self.task_queue.get()
|
||||
task_id = task.get("task_id")
|
||||
agent_id = task.get("agent_id")
|
||||
task_event = task.get("task_event")
|
||||
@@ -150,10 +140,7 @@ class WorkerCluster:
|
||||
self.results_futures[task_id] = future
|
||||
|
||||
task = {"task_id": task_id, "agent_id": agent_id, "task_event": task_event}
|
||||
if _STANDALONE:
|
||||
await self.task_queue.put(task)
|
||||
else:
|
||||
await self.task_queue.put_async(task)
|
||||
await self.task_queue.put(task)
|
||||
self.logger.debug(f"[WorkerCluster] 任务 {task_id} 已加入队列。")
|
||||
|
||||
try:
|
||||
@@ -168,5 +155,5 @@ class WorkerCluster:
|
||||
"active_worker_count": len(self._active_workers),
|
||||
"max_capacity": self.max_capacity,
|
||||
"cached_agent_ids": list(self._active_workers.keys()),
|
||||
"queue_size": self.task_queue.qsize() if _STANDALONE else self.task_queue.size(),
|
||||
"queue_size": self.task_queue.qsize() if self.task_queue else 0,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user