I have 50 workers running in Kubernetes, each work...
# ask-ai
g
I have 50 workers running in Kubernetes, each worker with 4-core CPU. They are running alright but i notice in the 50 workers, some are more idle than the others. Attached images are examples of 2 workers, one is very "busy" and the other is idle most of the time. The idle worker use less CPU and also process fewer jobs. My Worker Options settings are: • num_idle_processes = 0 • load_threshold = 0.5 What is the possible causes for uneven job distribution?
t
Thanks for reaching out, Kim. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand how uneven job distribution among your Kubernetes workers can be a bit frustrating. Let’s walk through some common reasons this might happen, based on your Worker Options settings and how the platform behaves: • Worker Load Monitoring: Each worker checks its own load using a CPU utilization function. When a worker’s load goes above the
load_threshold
, it stops taking on new jobs, which can cause the distribution to feel uneven. • Dynamic Idle Process Adjustment: The
num_idle_processes
adjusts dynamically depending on the worker’s current load. So, workers with lighter loads might keep more idle processes ready and end up receiving more jobs. • Per-Worker Load Calculation: Load is calculated individually for each worker, not across the whole cluster. This means some pods might be underused while others are busier. • Job Distribution Mechanism: Jobs get assigned in a round-robin style, but if some workers respond slower because of high load or latency, they might get fewer jobs. • Autoscaling Misalignment: If your Kubernetes autoscaling metrics don’t quite match the worker’s load function, the scaling might not balance the workload as well as you’d like. To help smooth things out, I’d suggest aligning your Kubernetes autoscaling metrics with the worker’s load function and thresholds. Also, keeping an eye on CPU usage and how long processes take to start can help you spot where bottlenecks might be. Sources: Worker options | LiveKit Docs | livekit-agents/livekit/agents/ipc/proc_pool.py | Deploying to custom environments | LiveKit Docs
g
we do not have Autoscaling at the moment, the number of workers is fixed at 50 at startup. considering that, how can i improve the distribution of jobs?
t
To help you improve job distribution among your fixed 50 Kubernetes workers, here are some friendly suggestions you might find useful: • Leverage Load-Based Distribution: LiveKit uses a weighted load-balancing strategy to assign jobs, favoring workers with lighter loads. It’s a good idea to check that this mechanism is working smoothly for you. • Customize the Load Function: You can define a custom
load_fnc
to calculate load based on what matters most for your workload, like memory usage or how many jobs are running concurrently. For instance, setting a limit on the number of concurrent jobs per worker can make a big difference. • Adjust Load Threshold: Try lowering the
load_threshold
(say, to 0.6) so workers start shedding load a bit earlier. This can help your system respond better and balance jobs more evenly. • Monitor Worker Metrics: Keeping an eye on CPU usage, memory, and job throughput regularly can really help you spot any bottlenecks and fine-tune your setup. • Graceful Shutdown: Setting
terminationGracePeriodSeconds
in your Kubernetes pod spec lets in-progress jobs finish during updates, which helps avoid uneven load distribution. Making these tweaks should help your job distribution feel smoother and more balanced across your workers, all without needing to scale up automatically. If you have any questions or want to dive deeper into any step, I’m here to help! Sources: pkg/service/agentservice.go | Worker options | LiveKit Docs | livekit-agents/livekit/agents/worker.py | Deploying to custom environments | LiveKit Docs