able-lighter-67088
07/29/2025, 5:47 PMtall-airline-16756
07/29/2025, 5:47 PMtall-airline-16756
07/29/2025, 5:48 PMagent.py worker can support, you can configure this through the WorkerOptions class using load management parameters.
Using WorkerOptions for Concurrency Control
The WorkerOptions class provides parameters to control how many concurrent agent instances a worker can handle:
opts = WorkerOptions(
entrypoint_fnc=your_entrypoint,
# Function that reports the current system load (CPU, RAM, etc.)
load_fnc=your_load_function,
# Maximum load value - above this, new processes will not spawn
load_threshold=your_threshold_value,
# Other options...
)
How Worker Concurrency Works
• Load Monitoring: The load_fnc parameter allows you to define a function that reports current system load (whether CPU, RAM, or other metrics).
• Load Threshold: The load_threshold parameter sets the maximum value of your load function—above this threshold, new processes will not spawn.
• Automatic Load Management: When a worker experiences high load, it stops taking on new sessions and notifies LiveKit's server.
System-Level Concurrency
LiveKit's dispatch system is optimized for high concurrency and low latency, supporting hundreds of thousands of new connections per second with dispatch times typically under 150ms. The framework automatically handles load balancing across available workers in the pool.
Example Implementation
Based on the agent.py example, you would configure concurrency when calling `cli.run_app()`:
if __name__ == "__main__":
cli.run_app(WorkerOptions(
entrypoint_fnc=entrypoint,
load_fnc=your_custom_load_function,
load_threshold=your_desired_threshold
))
The specific implementation of load_fnc and load_threshold values would depend on your system resources and desired concurrency limits.able-lighter-67088
07/29/2025, 5:49 PMtall-airline-16756
07/29/2025, 5:50 PMagent.py workers. I've got some awesome documentation links that'll make this super clear.
• Worker Options Documentation: Want to know how to manage your worker's concurrency like a pro? Check out this section that breaks down cool parameters like load_fnc and load_threshold. You can dive into all the details at Worker Options Documentation.
• Worker Lifecycle Documentation: Curious about how workers juggle multiple jobs? This section is your go-to guide for understanding process isolation and load balancing. Swing by Worker Lifecycle Documentation to get the full scoop.
Trust me, these resources are packed with practical examples that'll help you set up and manage worker concurrency like a champ!
Sources: Worker options | LiveKit Docs | Worker lifecycle | LiveKit Docs