[Metrics] Add admission rejection metrics (#55812)
Signed-off-by: Thuongvu Ho <thuongvuho@gmail.com> Co-authored-by: Nicolò Lucchesi <nicolo.lucchesi@mistral.ai>
This commit is contained in:
co-authored by
Nicolò Lucchesi
parent
5bed289707
commit
99b44c7a42
@@ -348,7 +348,7 @@ class AsyncLLM(EngineClient):
|
||||
else self.get_num_unfinished_requests()
|
||||
)
|
||||
if current_requests + n > max_num_reqs:
|
||||
logger.info(
|
||||
logger.debug(
|
||||
"Request queue full - rejecting request %s "
|
||||
"(current=%d, n=%d, max=%d).",
|
||||
request_id,
|
||||
@@ -356,21 +356,28 @@ class AsyncLLM(EngineClient):
|
||||
n,
|
||||
max_num_reqs,
|
||||
)
|
||||
self._record_admission_rejection("max_num_queued_reqs")
|
||||
raise QueueOverflowError()
|
||||
|
||||
max_queued_tokens = self.scheduler_config.max_num_queued_tokens
|
||||
if max_queued_tokens is not None:
|
||||
current_tokens = self.get_num_queued_tokens()
|
||||
if current_tokens >= max_queued_tokens:
|
||||
logger.info(
|
||||
logger.debug(
|
||||
"Max queued tokens reached - rejecting request %s "
|
||||
"(current_tokens=%d, max=%d).",
|
||||
request_id,
|
||||
current_tokens,
|
||||
max_queued_tokens,
|
||||
)
|
||||
self._record_admission_rejection("max_num_queued_tokens")
|
||||
raise MaxQueuedTokensError()
|
||||
|
||||
def _record_admission_rejection(self, reason: str) -> None:
|
||||
"""Increment the frontend admission rejection counter if logging is on."""
|
||||
if self.logger_manager is not None:
|
||||
self.logger_manager.record_admission_rejection(reason)
|
||||
|
||||
async def get_supported_tasks(self) -> tuple[SupportedTask, ...]:
|
||||
if not hasattr(self, "_supported_tasks"):
|
||||
# Cache the result
|
||||
|
||||
@@ -43,6 +43,9 @@ logger = init_logger(__name__)
|
||||
WAITING_REASON_CAPACITY = "capacity"
|
||||
WAITING_REASON_DEFERRED = "deferred"
|
||||
|
||||
# User-facing reason labels for frontend admission rejections.
|
||||
ADMISSION_REASONS = ("max_num_queued_reqs", "max_num_queued_tokens")
|
||||
|
||||
PerEngineStatLoggerFactory = Callable[[VllmConfig, int], "StatLoggerBase"]
|
||||
AggregateStatLoggerFactory = type["AggregateStatLoggerBase"]
|
||||
StatLoggerFactory = AggregateStatLoggerFactory | PerEngineStatLoggerFactory
|
||||
@@ -102,6 +105,9 @@ class AggregateStatLoggerBase(StatLoggerBase):
|
||||
@abstractmethod
|
||||
def __init__(self, vllm_config: VllmConfig, engine_indexes: list[int]): ...
|
||||
|
||||
def record_admission_rejection(self, reason: str) -> None: # noqa
|
||||
"""Record a frontend admission rejection. Optional for custom loggers."""
|
||||
|
||||
|
||||
class LoggingStatLogger(StatLoggerBase):
|
||||
def __init__(self, vllm_config: VllmConfig, engine_index: int = 0):
|
||||
@@ -816,6 +822,23 @@ class PrometheusStatLogger(AggregateStatLoggerBase):
|
||||
"request_num_preemptions", overrides=custom_buckets
|
||||
)
|
||||
|
||||
#
|
||||
# Frontend admission
|
||||
#
|
||||
counter_admission_rejections = self._counter_cls(
|
||||
name="vllm:admission_rejections",
|
||||
documentation=(
|
||||
"Number of admission attempts rejected by a queue limit, by reason."
|
||||
),
|
||||
labelnames=["model_name", "reason"],
|
||||
)
|
||||
self.admission_rejections = {
|
||||
reason: counter_admission_rejections.labels(
|
||||
model_name=model_name, reason=reason
|
||||
)
|
||||
for reason in ADMISSION_REASONS
|
||||
}
|
||||
|
||||
#
|
||||
# Histograms of counts
|
||||
#
|
||||
@@ -1276,6 +1299,9 @@ class PrometheusStatLogger(AggregateStatLoggerBase):
|
||||
finished_request.max_tokens_param
|
||||
)
|
||||
|
||||
def record_admission_rejection(self, reason: str) -> None:
|
||||
self.admission_rejections[reason].inc()
|
||||
|
||||
def record_sleep_state(self, sleep: int = 0, level: int = 0):
|
||||
awake = 1
|
||||
discard_all = 0
|
||||
@@ -1383,6 +1409,11 @@ class StatLoggerManager:
|
||||
for logger in self.stat_loggers:
|
||||
logger.record_sleep_state(sleep, level)
|
||||
|
||||
def record_admission_rejection(self, reason: str) -> None:
|
||||
"""Record one frontend admission rejection on aggregate loggers."""
|
||||
for stat_logger in self.stat_loggers:
|
||||
stat_logger.record_admission_rejection(reason)
|
||||
|
||||
def log(self):
|
||||
for logger in self.stat_loggers:
|
||||
logger.log()
|
||||
|
||||
Reference in New Issue
Block a user