MCPcopy Create free account
hub / github.com/TheSmallHanCat/flow2api / _get_token_load

Method _get_token_load

src/services/load_balancer.py:59–87  ·  view source on GitHub ↗

获取 token 当前负载。 Returns: (inflight, remaining) remaining 为 None 表示无限制

(self, token_id: int, for_image_generation: bool, for_video_generation: bool)

Source from the content-addressed store, hash-verified

57 self._video_pending[token_id] = current - 1
58
59 async def _get_token_load(self, token_id: int, for_image_generation: bool, for_video_generation: bool) -> tuple[int, Optional[int]]:
60 """获取 token 当前负载。
61
62 Returns:
63 (inflight, remaining)
64 remaining 为 None 表示无限制
65 """
66 if not self.concurrency_manager:
67 return 0, None
68
69 if for_image_generation:
70 inflight = await self.concurrency_manager.get_image_inflight(token_id)
71 remaining = await self.concurrency_manager.get_image_remaining(token_id)
72 pending = await self._get_pending_count(token_id, True, False)
73 effective_inflight = inflight + pending
74 if remaining is not None:
75 remaining = max(0, remaining - pending)
76 return effective_inflight, remaining
77
78 if for_video_generation:
79 inflight = await self.concurrency_manager.get_video_inflight(token_id)
80 remaining = await self.concurrency_manager.get_video_remaining(token_id)
81 pending = await self._get_pending_count(token_id, False, True)
82 effective_inflight = inflight + pending
83 if remaining is not None:
84 remaining = max(0, remaining - pending)
85 return effective_inflight, remaining
86
87 return 0, None
88
89 async def _reserve_slot(self, token_id: int, for_image_generation: bool, for_video_generation: bool) -> bool:
90 """尝试为当前 token 预占一个生成槽位。"""

Callers 1

select_tokenMethod · 0.95

Calls 5

_get_pending_countMethod · 0.95
get_image_inflightMethod · 0.80
get_image_remainingMethod · 0.80
get_video_inflightMethod · 0.80
get_video_remainingMethod · 0.80

Tested by

no test coverage detected