Rename _alive_streaming_session_count; use _is_streaming helper (#22755)

This commit is contained in:
Liangsheng Yin
2026-04-14 13:26:03 -07:00
committed by GitHub
parent 0cb7295698
commit 36891ab514
5 changed files with 8 additions and 10 deletions
@@ -134,7 +134,7 @@ class PoolStats:
class SchedulerRuntimeCheckerMixin:
def _alive_streaming_session_count(self: Scheduler) -> int:
def _streaming_session_count(self: Scheduler) -> int:
return sum(
1
for session in self.session_controller.sessions.values()
@@ -506,7 +506,7 @@ class SchedulerRuntimeCheckerMixin:
return
self.get_pool_stats().update_scheduler_stats(self.stats)
self.stats.num_streaming_sessions = self._alive_streaming_session_count()
self.stats.num_streaming_sessions = self._streaming_session_count()
self.stats.streaming_session_held_tokens = self._session_held_tokens()
priority_enabled = self.enable_priority_scheduling
@@ -312,7 +312,7 @@ class SessionController:
)
return
# No active request -- safe to release immediately.
# No owning request -- safe to release immediately.
if session.streaming and session.req_nodes:
req = next(iter(session.req_nodes.values())).req
req.session = None
+3 -5
View File
@@ -9,7 +9,7 @@ import triton.language as tl
from sglang.srt.mem_cache.base_prefix_cache import BasePrefixCache, EvictParams
from sglang.srt.mem_cache.memory_pool import HybridReqToTokenPool, ReqToTokenPool
from sglang.srt.mem_cache.session_aware_cache import SessionAwareCache
from sglang.srt.mem_cache.session_aware_cache import SessionAwareCache, _is_streaming
from sglang.srt.mem_cache.swa_memory_pool import SWATokenToKVPoolAllocator
from sglang.srt.server_args import get_global_server_args
from sglang.srt.utils import support_triton
@@ -487,10 +487,8 @@ def release_kv_cache(req: Req, tree_cache: BasePrefixCache, is_insert: bool = Tr
# cache_finished_req below (which also sets req_pool_idx = None).
from sglang.srt.managers.schedule_batch import FINISH_ABORT
is_streaming_session = (
isinstance(tree_cache, SessionAwareCache)
and getattr(req, "session", None) is not None
and req.session.streaming
is_streaming_session = isinstance(tree_cache, SessionAwareCache) and _is_streaming(
req
)
is_aborted_streaming = is_streaming_session and isinstance(
getattr(req, "finished_reason", None), FINISH_ABORT
@@ -686,7 +686,7 @@ class SchedulerMetricsCollector:
if self.enable_streaming_session:
self.num_streaming_sessions = Gauge(
name="sglang:num_streaming_sessions",
documentation="The number of active streaming sessions.",
documentation="The number of streaming sessions.",
labelnames=labels.keys(),
multiprocess_mode="mostrecent",
)
@@ -604,7 +604,7 @@ class SchedulerMetricsMixin:
self.stats.cache_hit_rate = cache_hit_rate
self.stats.max_total_num_tokens = self.max_total_num_tokens
self.stats.num_streaming_sessions = self._alive_streaming_session_count()
self.stats.num_streaming_sessions = self._streaming_session_count()
self.stats.streaming_session_held_tokens = self._session_held_tokens()
# Speculative decoding