Skip to content

Commit

Permalink
[Bugfix] Update QPS when no requests (#174)
Browse files Browse the repository at this point in the history
Signed-off-by: Shaoting Feng <[email protected]>
  • Loading branch information
Shaoting-Feng authored Feb 27, 2025
1 parent fd56e78 commit 14e3849
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/vllm_router/request_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ def update(self, timestamp: float, value: float):
self.timestamps.popleft()
self.values.popleft()

def update_no_value(self, timestamp: float):
"""
Update the throughput monitor with a new timestamp with no value
"""
while (
len(self.timestamps) > 0
and self.timestamps[0] < timestamp - self.sliding_window_size
):
self.timestamps.popleft()
self.values.popleft()

def get_average(self) -> float:
return sum(self.values) / len(self.values) if self.values else -1

Expand Down Expand Up @@ -221,11 +232,15 @@ def get_request_stats(self, current_time: float) -> Dict[str, RequestStats]:
if engine_url not in self.qps_monitors:
qps = -1
else:
# Update the monitors
self.qps_monitors[engine_url].update_no_value(current_time)
qps = self.qps_monitors[engine_url].get_sum() / self.sliding_window_size

if engine_url not in self.ttft_monitors:
ttft = -1
else:
# Update the monitors
self.ttft_monitors[engine_url].update_no_value(current_time)
ttft = self.ttft_monitors[engine_url].get_average()

in_prefill = self.in_prefill_requests.get(engine_url, 0)
Expand Down

0 comments on commit 14e3849

Please sign in to comment.