Skip to content

Commit fab395b

Browse files
committed
perf(trtllm): reduce futile loop iterations
The executor_status_looper runs a spin loop, even if there are no active requests. This makes the service constantly wasting a CPU core. Make the loop block on receiving requests if there are no running ones to reduce CPU usage when idle.
1 parent f7bd82a commit fab395b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

backends/trtllm/src/looper.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ fn executor_status_looper(
9090

9191
'scheduler: loop {
9292
// Is there any request pending to be scheduled?
93-
let awaiting_requests = backlog.len();
93+
let mut awaiting_requests = backlog.len();
94+
if awaiting_requests == 0 && in_flights.is_empty() {
95+
// Wait for 1 request if we are not waiting for any response,
96+
// so that the loop blocks at receive from backlog.
97+
awaiting_requests += 1;
98+
}
9499
for _ in 0..awaiting_requests {
95100
// Retrieve all the requests
96101
if let Some(ctx) = backlog.blocking_recv() {

0 commit comments

Comments
 (0)