[Feat] Add received_time in serving_base (#13432)

Signed-off-by: zhanghaotong <zhanghaotong.zht@antgroup.com>
This commit is contained in:
zhanghaotong
2025-12-09 21:00:24 +08:00
committed by GitHub
parent cef5ba65b1
commit fe7f91ef82
3 changed files with 16 additions and 1 deletions

View File

@@ -88,6 +88,9 @@ class OpenAIServingBase(ABC):
"""Handle the specific request type with common pattern
If you want to override this method, you should be careful to record the validation time.
"""
received_time = time.time()
received_time_perf = time.perf_counter()
try:
# Validate request
validation_start = time.perf_counter()
@@ -103,6 +106,12 @@ class OpenAIServingBase(ABC):
if hasattr(adapted_request, "validation_time"):
adapted_request.validation_time = validation_time
if hasattr(adapted_request, "received_time"):
adapted_request.received_time = received_time
if hasattr(adapted_request, "received_time_perf"):
adapted_request.received_time_perf = received_time_perf
# Note(Xinyuan): raw_request below is only used for detecting the connection of the client
if hasattr(request, "stream") and request.stream:
return await self._handle_streaming_request(

View File

@@ -204,6 +204,12 @@ class GenerateReqInput(BaseReq):
# Validation step duration
validation_time: Optional[float] = None
# For metrics
received_time: Optional[float] = None
# Perf_counter equivalents for accurate time calculations
received_time_perf: Optional[float] = None
# For data parallel rank routing
data_parallel_rank: Optional[int] = None

View File

@@ -431,7 +431,7 @@ class TokenizerManager(TokenizerCommunicatorMixin):
obj: Union[GenerateReqInput, EmbeddingReqInput],
request: Optional[fastapi.Request] = None,
):
created_time = time.time()
created_time = obj.received_time if obj.received_time else time.time()
self.auto_create_handle_loop()
obj.normalize_batch_and_arguments()