gray-magician-34629
11/25/2025, 6:57 AMtall-airline-16756
11/25/2025, 6:57 AMtall-airline-16756
11/25/2025, 6:58 AMload_fnc and load_threshold so an agent rejects new jobs when its load is high. Example pattern:
def compute_load(server):
return min(len(server.active_jobs) / 10, 1.0) # scale by max sessions
server = AgentServer(load_fnc=compute_load, load_threshold=0.9)
• This causes LiveKit to dispatch new rooms to other available agents once an instance reaches capacity.
3) Graceful drain on shutdown/rollouts
• Set a drain timeout so tasks finish existing rooms before deregistering (avoid sudden concentration of rooms on the remaining agents).
• Example: AgentServer(drain_timeout=600) to allow in-flight sessions to complete.
4) Monitor and scale
• Monitor CPU and active job counts per ECS task (CloudWatch/custom metrics). If average sessions per agent approach ~10–25 depending on instance size, scale out.
• Choose non-burstable instance types (e.g., c5/m5) for consistent CPU performance.
5) Avoid sticky room routing
• If many clients reconnect to the same room name, they will be routed to the agent currently hosting that room. Use unique room IDs per session or ensure rooms are closed when sessions end if you want the scheduler to rebalance.
If you’d like, tell me:
• what ECS instance types you’re using,
• how many concurrent rooms/sessions you see per agent,
• and whether agents report themselves as healthy in the LiveKit server logs —
and I’ll suggest concrete load_fnc parameters and scaling guidance.
Sources: Deploying to custom environments | LiveKit Docs | Agent server options | LiveKit docs | Troubleshooting Latency and Timeout Errors with Turn Detection on AWS | Agent server | LiveKit docsgray-magician-34629
11/25/2025, 6:59 AMtall-airline-16756
11/25/2025, 7:00 AMload_fnc is provided, the agent uses average CPU utilization over a 5‑second window as its load metric. The default load_threshold is 0.7 (70%), so the agent will stop accepting new jobs while its CPU load remains above 70%.
Sources: Agent server options | LiveKit docs | Deploying to custom environments | LiveKit Docsgray-magician-34629
11/25/2025, 7:00 AMtall-airline-16756
11/25/2025, 7:00 AMload_fnc that returns 1.0 when your measured metric (e.g., process CPU, active_sessions) exceeds your capacity so the agent immediately rejects new jobs.
• Example approach: stop accepting new jobs when process CPU > 75% or active sessions > N.
def compute_load(server):
proc_cpu = get_process_cpu_percent() # your implementation
if proc_cpu > 75:
return 1.0
return proc_cpu / 75.0
server = AgentServer(load_fnc=compute_load, load_threshold=0.9)
5) Longer-term fixes
• Scale out ECS tasks or use larger instance types (c5/m5) to keep per-agent sessions below ~10–25 depending on workload.
• Ensure graceful drain during deploys so remaining agents don’t get overloaded.
If you want, tell me:
• ECS instance type and whether tasks have CPU limits,
• whether agents’ logs show load reporting/registration,
• and the LiveKit agent version —
I’ll recommend a concrete load_fnc and threshold and specific monitoring checks.