[Core][Metrics] expose waiting request breakdown via labeled metric (capacity/deferred) (#38435)

Signed-off-by: Mukesh Baphna <mukesh@hippocraticai.com>
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Mark McLoughlin <markmc@redhat.com>
This commit is contained in:
mukesh-hai
2026-04-13 15:30:55 -04:00
committed by GitHub
co-authored by Claude Sonnet 4.6 Mark McLoughlin
parent f72b20976c
commit 5c18b961d6
5 changed files with 101 additions and 4 deletions
+2 -1
View File
@@ -1955,7 +1955,8 @@ class Scheduler(SchedulerInterface):
)
return SchedulerStats(
num_running_reqs=len(self.running),
num_waiting_reqs=len(self.waiting) + len(self.skipped_waiting),
num_waiting_reqs=len(self.waiting),
num_skipped_waiting_reqs=len(self.skipped_waiting),
kv_cache_usage=self.kv_cache_manager.usage,
encoder_cache_usage=self._get_encoder_cache_usage(),
prefix_cache_stats=prefix_cache_stats,
+47 -2
View File
@@ -32,6 +32,10 @@ from vllm.v1.spec_decode.metrics import SpecDecodingLogging, SpecDecodingProm
logger = init_logger(__name__)
# User-facing reason labels for waiting request breakdown
WAITING_REASON_CAPACITY = "capacity"
WAITING_REASON_DEFERRED = "deferred"
PerEngineStatLoggerFactory = Callable[[VllmConfig, int], "StatLoggerBase"]
AggregateStatLoggerFactory = type["AggregateStatLoggerBase"]
StatLoggerFactory = AggregateStatLoggerFactory | PerEngineStatLoggerFactory
@@ -222,13 +226,21 @@ class LoggingStatLogger(StatLoggerBase):
"Running: %d reqs",
"Waiting: %d reqs",
]
total_waiting = (
self.last_scheduler_stats.num_waiting_reqs
+ self.last_scheduler_stats.num_skipped_waiting_reqs
)
log_args: list[int | float | str] = [
self.last_prompt_throughput,
self.last_generation_throughput,
self.last_scheduler_stats.num_running_reqs,
self.last_scheduler_stats.num_waiting_reqs,
total_waiting,
]
if self.last_scheduler_stats.num_skipped_waiting_reqs > 0:
log_parts.append("Deferred: %d reqs")
log_args.append(self.last_scheduler_stats.num_skipped_waiting_reqs)
if self.num_preemptions > 0:
log_parts.append("Preemptions: %d")
log_args.append(self.num_preemptions)
@@ -328,6 +340,9 @@ class AggregatedLoggingStatLogger(LoggingStatLogger, AggregateStatLoggerBase):
self.last_scheduler_stats.num_running_reqs += (
last_scheduler_stats.num_running_reqs
)
self.last_scheduler_stats.num_skipped_waiting_reqs += (
last_scheduler_stats.num_skipped_waiting_reqs
)
self.last_scheduler_stats.kv_cache_usage += (
last_scheduler_stats.kv_cache_usage
)
@@ -453,6 +468,28 @@ class PrometheusStatLogger(AggregateStatLoggerBase):
gauge_scheduler_waiting, per_engine_labelvalues
)
gauge_waiting_by_reason = self._gauge_cls(
name="vllm:num_requests_waiting_by_reason",
documentation=(
"Number of waiting requests by reason. "
"Reason labels: 'capacity' = waiting for scheduling capacity; "
"'deferred' = deferred by transient constraints "
"(LoRA budget, KV transfer, blocked status). "
"Sum of all reasons equals vllm:num_requests_waiting."
),
multiprocess_mode="mostrecent",
labelnames=labelnames + ["reason"],
)
self.gauge_waiting_by_reason: dict[str, dict[int, Gauge]] = {}
for waiting_reason in [WAITING_REASON_CAPACITY, WAITING_REASON_DEFERRED]:
per_engine_labelvalues_with_reason = {
idx: labelvalues + [waiting_reason]
for idx, labelvalues in per_engine_labelvalues.items()
}
self.gauge_waiting_by_reason[waiting_reason] = create_metric_per_engine(
gauge_waiting_by_reason, per_engine_labelvalues_with_reason
)
gauge_engine_sleep_state = self._gauge_cls(
name="vllm:engine_sleep_state",
documentation=(
@@ -1030,8 +1067,16 @@ class PrometheusStatLogger(AggregateStatLoggerBase):
self.gauge_scheduler_running[engine_idx].set(
scheduler_stats.num_running_reqs
)
self.gauge_scheduler_waiting[engine_idx].set(
total_waiting = (
scheduler_stats.num_waiting_reqs
+ scheduler_stats.num_skipped_waiting_reqs
)
self.gauge_scheduler_waiting[engine_idx].set(total_waiting)
self.gauge_waiting_by_reason[WAITING_REASON_CAPACITY][engine_idx].set(
scheduler_stats.num_waiting_reqs
)
self.gauge_waiting_by_reason[WAITING_REASON_DEFERRED][engine_idx].set(
scheduler_stats.num_skipped_waiting_reqs
)
self.gauge_kv_cache_usage[engine_idx].set(scheduler_stats.kv_cache_usage)
+3 -1
View File
@@ -172,7 +172,9 @@ class SchedulerStats:
"""Stats associated with the scheduler."""
num_running_reqs: int = 0
num_waiting_reqs: int = 0
num_waiting_reqs: int = 0 # length of the "waiting" request queue
num_skipped_waiting_reqs: int = 0 # length of the "skipped waiting" queue
# These are used for internal DP load-balancing.
step_counter: int = 0