Some of my agents are not getting closed and this ...
# ask-ai
g
Some of my agents are not getting closed and this is causing horizontal scaling of my self hosted livekit setup. What am i missing? What should be idea WorkerOptions configuration for Production setup
t
Thanks for reaching out, Rishi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Setting up a production environment with a self-hosted LiveKit can feel a bit overwhelming, but I’m here to help you through it! When configuring your
WorkerOptions
, focusing on stability, resource management, and scalability will really pay off. Here are some friendly recommendations to guide you: • Set
production: true
to activate those helpful production-specific defaults. • Load Threshold: Try using
loadThreshold: 0.7
to keep your workers from getting overloaded. • Idle Processes: Matching
numIdleProcesses
to your number of CPU cores usually gives you smooth performance. • Memory Management: It’s a good idea to set
jobMemoryWarnMB
(around 500MB) and, if you want,
jobMemoryLimitMB
to keep an eye on memory usage. • Health Checks: Stick with the default port
8081
for monitoring the health of your workers. • Timeouts: Consider setting
shutdownProcessTimeout
to 60 seconds and
initializeProcessTimeout
to 10 seconds to help with graceful scaling and startup. • Secure Configuration: For your safety, use environment variables for
LIVEKIT_API_KEY
,
LIVEKIT_API_SECRET
, and
LIVEKIT_URL
instead of hardcoding them. One more tip: make sure your
wsURL
points to your LiveKit server (like
wss://livekit.yourdomain.com
) and that you have valid SSL certificates in place. As you go along, keep an eye on how your setup performs under real-world load and feel free to tweak
numIdleProcesses
and memory settings to find what works best for you. Sources: agents/src/worker.ts | livekit-agents/livekit/agents/worker.py | Deploying to custom environments | LiveKit Docs | Deploying LiveKit | LiveKit Docs | Worker options | LiveKit Docs