Skip to content

Commit c5f5589

Browse files
llama-router: separate PROCESS (OS) and BACKEND (HTTP) polling constants
ROUTER_POLL_INTERVAL_MS -> ROUTER_PROCESS_POLL_INTERVAL_MS PROCESS = OS operations (PID, fork, kill) BACKEND = HTTP operations (health, readiness) Adjust timeouts: 2s shutdown, 60s ready, 100ms polls
1 parent 3d39d76 commit c5f5589

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

tools/router/ARCHITECTURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ This aligns with the project philosophy: **everything configurable at runtime, z
9393

9494
- **Spawn**: `fork()`/`CreateProcess()` with stdout/stderr capture
9595
- **Health polling**: `ROUTER_BACKEND_HEALTH_POLL_MS` intervals, `ROUTER_BACKEND_READY_TIMEOUT_MS` timeout
96-
- **Graceful shutdown**: SIGTERM → wait `ROUTER_PROCESS_SHUTDOWN_TIMEOUT_MS` → SIGKILL → poll every `ROUTER_POLL_INTERVAL_MS` until exit
96+
- **Graceful shutdown**: SIGTERM → wait `ROUTER_PROCESS_SHUTDOWN_TIMEOUT_MS` → SIGKILL → poll every `ROUTER_PROCESS_POLL_INTERVAL_MS` until exit
9797
- **Cleanup**: File descriptors closed, waitpid() called
9898

9999
---

tools/router/router-constants.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#pragma once
22

3+
// Polling interval in milliseconds used for backend health checks during startup.
4+
#define ROUTER_BACKEND_HEALTH_POLL_MS 100
5+
36
// Polling interval in milliseconds used for process exit checks and shutdown loops.
4-
#define ROUTER_POLL_INTERVAL_MS 100
7+
#define ROUTER_PROCESS_POLL_INTERVAL_MS 100
58

69
// Maximum time in milliseconds to wait for a process to terminate gracefully before forcing shutdown.
7-
#define ROUTER_PROCESS_SHUTDOWN_TIMEOUT_MS 1000
10+
#define ROUTER_PROCESS_SHUTDOWN_TIMEOUT_MS 2000
811

912
// Maximum time in milliseconds to wait for a backend to report readiness.
10-
#define ROUTER_BACKEND_READY_TIMEOUT_MS 10000
11-
12-
// Polling interval in milliseconds used for backend health checks during startup.
13-
#define ROUTER_BACKEND_HEALTH_POLL_MS 200
13+
#define ROUTER_BACKEND_READY_TIMEOUT_MS 60000

tools/router/router-process.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool wait_for_process_exit(const ProcessHandle & handle, int timeout_ms) {
6363
if (std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count() > timeout_ms) {
6464
return false;
6565
}
66-
std::this_thread::sleep_for(std::chrono::milliseconds(ROUTER_POLL_INTERVAL_MS));
66+
std::this_thread::sleep_for(std::chrono::milliseconds(ROUTER_PROCESS_POLL_INTERVAL_MS));
6767
}
6868
#endif
6969
}
@@ -133,7 +133,7 @@ void terminate_process(ProcessHandle & handle) {
133133
LOG_ERR("Process pid=%d did not terminate, sending SIGKILL\n", static_cast<int>(handle.pid));
134134
kill(handle.pid, SIGKILL);
135135
while (process_running(handle)) {
136-
std::this_thread::sleep_for(std::chrono::milliseconds(ROUTER_POLL_INTERVAL_MS));
136+
std::this_thread::sleep_for(std::chrono::milliseconds(ROUTER_PROCESS_POLL_INTERVAL_MS));
137137
}
138138
}
139139
close_process(handle);

0 commit comments

Comments
 (0)