delightful-planet-44653
12/24/2025, 11:23 AMlen(worker.active_jobs) an accurate way to know how many requests a worker is currently processing?tall-airline-16756
12/24/2025, 11:23 AMtall-airline-16756
12/24/2025, 11:24 AMlen(worker.active_jobs) accurately reflects how many requests (active jobs/sessions) that worker is currently processing. LiveKit’s agent worker tracks running jobs in active_jobs, and many setups use len(worker.active_jobs) in load functions (for example: len(worker.active_jobs) / max_concurrent_jobs) to decide worker availability and limit concurrency.
Sources: Agent server options | LiveKit docsdelightful-planet-44653
12/24/2025, 11:24 AMmax_concurrent_jobs?tall-airline-16756
12/24/2025, 11:25 AMmax_concurrent_jobs setting. You control concurrency by providing a custom load_fnc and setting load_threshold on your AgentServer. For example, to cap at ~9 concurrent jobs:
def compute_load(agent_server: AgentServer) -> float:
return min(len(agent_server.active_jobs) / 9, 1.0)
server = AgentServer(load_threshold=0.9)
server.load_fnc = compute_load
Note: load_fnc and load_threshold are configurable only for self-hosted/custom deployments — they cannot be changed in LiveKit Cloud. Would you like help writing a load_fnc that fits your exact capacity or deployment setup?
Sources: Agent server options | LiveKit docsdelightful-planet-44653
12/24/2025, 11:27 AMactive_jobs_cnt = len(worker.active_jobs)
job_load = min(1.0, active_jobs_cnt / MAX_JOBS_PER_WORKER)
return job_load
Threshold is set to 0.7tall-airline-16756
12/24/2025, 11:27 AMserver.load_fnc and load_threshold).
• Any relevant logs around job assignment when the spike occurs (timestamps help).
• Whether jobs sometimes block or hang (long-running tasks) and typical job duration.
Likely causes and quick checks:
• Multiple worker instances: if multiple worker processes/containers share the same host, each has its own active_jobs — totals can exceed 10 across instances.
• Load evaluation timing: load_fnc is consulted when dispatching; concurrent dispatch decisions can race, temporarily allowing more than the intended number before load updates propagate.
• Threshold vs hard limit: load_threshold prevents further assignments once load > threshold but is not a strict hard cap; spikes above the implied MAX can occur briefly.
• Long-running or stuck jobs: if jobs aren't finishing, active_jobs will accumulate past the expected steady-state.
• Miswired function: ensure load_fnc reads agent_server.active_jobs (not a different worker object) and that MAX_JOBS_PER_WORKER value is correct in that context.
Immediate actions you can take:
• Add logging inside load_fnc to record len(agent_server.active_jobs) and returned load whenever called.
• Log job start/finish with job IDs and timestamps to detect stuck jobs or long tails.
• Temporarily reduce load_threshold (e.g., to 0.5) to lower the effective concurrency while you investigate.
• If you need a strict cap, enforce a guard inside job-acceptance code: reject new jobs when len(worker.active_jobs) >= MAX_JOBS_PER_WORKER.
If you share the startup snippet and any logs around a spike, I’ll review them and point out what to change.