-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Bug Description
We want to restrict our worker (AgentServer) to accept only one concurrent job at a time.
According to the LiveKit documentation (https://docs.livekit.io/agents/server/options/#agent-server-load), this can be achieved using load_threshold and load_fnc. See reproduction steps below.
However, we were able to reproduce situations where the AgentServer would still accept two jobs.
Problem
The problem lies in the interval where the server._worker_load variable is updated:
| interval = utils.aio.interval(UPDATE_LOAD_INTERVAL) |
The interval is set to 0.5s. If two job requests arrive within this interval, the _worker_load will be 0 for both and the server will accept both requests.
In the past few days I have tried many workarounds using multiprocessing Locks, Values, and other mechanisms, however I was unable to find a reliable solution to prevent this edge case behavior.
Questions:
- Is there an alternative to guarantee that only one job can run at a time?
- Could this functionality be provided natively?
Many thanks for your help!
Best, David
Expected Behavior
We would expect a solution that guarantees that only one job can be accepted at a time.
Reproduction Steps
# limit number of concurrent jobs using `load_threshold` and `load_fnc`:
from livekit.agents import AgentServer
server = AgentServer(
load_threshold=1.0,
)
def compute_load(server: AgentServer) -> float:
return float(len(server.active_jobs))
server.load_fnc=compute_load
The AgentServer can still accept two jobs**:
1. open two separate browser tabs
2. start two connection requests nearly exactly at the same time
3. => AgentServer will accept both jobsOperating System
Windows, Linux
Models Used
No response
Package Versions
livekit==1.1.2
livekit-agents>=1.4.2