Skip to content

Commit 4d7d063

Browse files
authored
feat: Make log stats interval as a hidden CLI argument (#49)
Signed-off-by: Ce Gao <[email protected]>
1 parent 6c3f402 commit 4d7d063

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/vllm_router/router.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ async def process_request(
6464
content=body,
6565
timeout=None,
6666
) as backend_response:
67-
6867
yield backend_response.headers, backend_response.status_code
6968

7069
# Stream response content
@@ -215,6 +214,15 @@ def validate_args(args):
215214
"Session key must be provided when using session routing logic."
216215
)
217216

217+
if args.log_stats and args.log_stats_interval <= 0:
218+
raise ValueError("Log stats interval must be greater than 0.")
219+
220+
if args.engine_stats_interval <= 0:
221+
raise ValueError("Engine stats interval must be greater than 0.")
222+
223+
if args.request_stats_window <= 0:
224+
raise ValueError("Request stats window must be greater than 0.")
225+
218226

219227
def parse_args():
220228
parser = argparse.ArgumentParser(description="Run the FastAPI app.")
@@ -243,7 +251,7 @@ def parse_args():
243251
"--static-models",
244252
type=str,
245253
default=None,
246-
help="The models of static backends, separated by comma." "E.g., model1,model2",
254+
help="The models of static backends, separated by comma. E.g., model1,model2",
247255
)
248256
parser.add_argument(
249257
"--k8s-port",
@@ -295,7 +303,15 @@ def parse_args():
295303

296304
# Logging
297305
parser.add_argument(
298-
"--log-stats", action="store_true", help="Log statistics every 10 seconds."
306+
"--log-stats", action="store_true", help="Log statistics periodically."
307+
)
308+
309+
parser.add_argument(
310+
"--log-stats-interval",
311+
type=int,
312+
default=10,
313+
help="The interval in seconds to log statistics.",
314+
hidden=True,
299315
)
300316
args = parser.parse_args()
301317
validate_args(args)
@@ -349,9 +365,9 @@ def InitializeAll(args):
349365
raise ValueError(f"Invalid routing logic: {args.routing_logic}")
350366

351367

352-
def log_stats():
368+
def log_stats(interval: int = 10):
353369
while True:
354-
time.sleep(10)
370+
time.sleep(interval)
355371
logstr = "\n" + "=" * 50 + "\n"
356372
endpoints = GetServiceDiscovery().get_endpoint_info()
357373
engine_stats = GetEngineStatsScraper().get_engine_stats()
@@ -362,12 +378,12 @@ def log_stats():
362378
if url in engine_stats:
363379
logstr += f" Engine stats: {engine_stats[url]}\n"
364380
else:
365-
logstr += f" Engine stats: No stats available\n"
381+
logstr += " Engine stats: No stats available\n"
366382

367383
if url in request_stats:
368384
logstr += f" Request Stats: {request_stats[url]}\n"
369385
else:
370-
logstr += f" Request Stats: No stats available\n"
386+
logstr += " Request Stats: No stats available\n"
371387

372388
logstr += "-" * 50 + "\n"
373389
logstr += "=" * 50 + "\n"
@@ -380,7 +396,9 @@ def main():
380396
InitializeAll(args)
381397

382398
if args.log_stats:
383-
threading.Thread(target=log_stats, daemon=True).start()
399+
threading.Thread(
400+
target=log_stats, args=(args.log_stats_interval,), daemon=True
401+
).start()
384402

385403
uvicorn.run(app, host=args.host, port=args.port)
386404

0 commit comments

Comments
 (0)