explain _load_threshold in worker option_
# ask-ai
m
explain _load_threshold in worker option_
t
Thanks for reaching out, Alfred. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The load_threshold in the worker configuration controls when a LiveKit worker will stop accepting new jobs based on its load. The threshold is a number between 0 and 1; when the worker's
load_fnc
(which typically measures CPU or custom resource usage) exceeds this value, the worker is marked as unavailable for job assignments. • Default values: In production, defaults are 0.75 (Python) or 0.65 (JavaScript). In development, it is effectively disabled (infinity). • When the worker load exceeds
load_threshold
, the worker's status changes so it's no longer routed new jobs, supporting stable load balancing and resource protection. • You can pair
load_threshold
with a custom
load_fnc
to use metrics beyond CPU, such as running job count. • In production, set your autoscaling triggers lower than the
load_threshold
to ensure new workers are provisioned before existing ones reach their limit. This parameter is essential for balanced distribution and high availability in scaled deployments. For implementation details and practical configuration examples, refer to the sources for full context. • Python and JS worker behavior: see • Production scaling guidance: see Sources: Deploying to production | LiveKit Docs | WorkerOptions | LiveKit Agents | Worker options | LiveKit Docs | livekit-agents/livekit/agents/worker.py | agents/src/worker.ts
m
where can i see worker's default
load_fnc
?
t
Hey there! Let me walk you through how LiveKit workers handle their workload. 😊Python workers: Check out the
_DefaultLoadCalc
class in
livekit-agents/livekit/agents/worker.py
(lines 81–108). It's pretty neat how they calculate things! • Node.js workers: Their magic happens in the
defaultCpuLoad
function within
agents/src/worker.ts
(lines 79–111). Here's the cool part: both approaches look at CPU utilization. They're basically checking how hard your computer is working, using smart methods to track CPU percentage and return a value between 0 and 1. Think of it like a stress meter for your machine! 💻 This helps determine when a worker should take a break from accepting new jobs, based on the
load_threshold
. • Source details on function location and logic: • Default metric and value range: Sources: agents/src/worker.ts | Worker options | LiveKit Docs | Deployment and scaling | LiveKit Docs | livekit-agents/livekit/agents/worker.py