adorable-portugal-55771
09/02/2025, 8:41 AMtall-airline-16756
09/02/2025, 8:41 AMtall-airline-16756
09/02/2025, 8:42 AMadorable-portugal-55771
09/02/2025, 8:45 AMtall-airline-16756
09/02/2025, 8:46 AMload_fnc and load_threshold in WorkerOptions. For instance, if you want to limit a worker to 9 concurrent jobs, you can use a custom function like min(len(worker.active_jobs) / 10, 1.0) and set load_threshold to 0.9.
• By default, load_fnc calculates the average CPU usage over a 5-second window, and load_threshold is set to 0.7.
2. Scaling Workers
• Connect your setup with an autoscaler (like Kubernetes Horizontal Pod Autoscaler) and set scaling triggers a bit below your load_threshold. For example, if your threshold is 0.7, you might want to start scaling up at 0.5 to stay ahead.
• Don’t forget to tweak cooldown and stabilization windows: make them shorter when scaling up so your system reacts quickly to higher loads, and longer when scaling down to give active jobs enough time to finish gracefully.
3. Optimizing Resource Usage
• Keep some processes warm by setting num_idle_processes, which helps cut down cold start delays. On production Python agents, the default is up to 4 idle processes.
• Set drain_timeout (default is 30 minutes) so running jobs have a chance to wrap up nicely during shutdown.
• Based on load testing, a good rule of thumb is to allocate 4 cores for every 25 voice agents to keep things running smoothly.
If you’re using LiveKit Cloud, the good news is that it takes care of the operational complexity for you — the agent scheduler handles stateful load balancing. Just a heads up though, custom load_fnc and load_threshold settings aren’t supported there.
Need a hand setting this all up or want some tips tailored to your specific deployment? Just let me know—I’m here to help!
Sources: Worker options | LiveKit Docs | Deployment and scaling | LiveKit Docs | Deploying to custom environments | LiveKit Docs | Deploy and scale agents on LiveKit Cloud | Deploy and scale agents on LiveKit Cloud