Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions python/sglang/srt/entrypoints/openai/serving_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ async def handle_request(
"""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()
Expand All @@ -103,6 +106,12 @@ async def handle_request(
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(
Expand Down
6 changes: 6 additions & 0 deletions python/sglang/srt/managers/io_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion python/sglang/srt/managers/tokenizer_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ async def generate_request(
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()

Expand Down
Loading