Hey everyone, I’m currently facing an issue where...
# ask-ai
t
Hey everyone, I’m currently facing an issue where my project deployed on LiveKit Cloud is showing high memory usage in the error logs - even when the code isn’t actively running. Could anyone please help me understand the following: 1. What could be the possible reasons for this high memory usage? 2. How can I clear or manage the memory usage in LiveKit Cloud? Any insights or suggestions would be really appreciated. Thanks in advance!
t
Thanks for reaching out, Om. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand that high memory usage in LiveKit Cloud can be a bit concerning, especially when running agent workloads with demanding features like enhanced noise cancellation or turn detection. These features do require more CPU and memory, particularly when you have multiple sessions happening at the same time. To help you out, LiveKit Cloud automatically manages memory through several smart methods: • Process-level monitoring: Each agent process has configurable thresholds (memoryWarnMB and memoryLimitMB). If a process goes over the limit, the system gently stops it to keep everything stable. • Egress service management: Memory usage is tracked for each process, and if limits are exceeded, the system will stop the process using the most memory. • Automatic scaling: When servers get close to their limits, LiveKit Cloud automatically starts new instances and spreads out the traffic to avoid overload. Here are some friendly tips to optimize your memory usage: • Adjust the memoryWarnMB and memoryLimitMB settings based on what your workload needs. • Try to use the recommended hardware specs, like 4 CPU cores and 8GB RAM per worker, especially for voice AI applications. • Take advantage of LiveKit Cloud’s elastic scaling to smoothly handle capacity changes. • Keep an eye on memory and performance metrics through the LiveKit Cloud dashboard to stay informed. Since memory is managed automatically, there’s no manual clearing needed. By fine-tuning your agent code and setting the right thresholds, you can help keep memory usage in check and your system running smoothly. If you have any questions or need further guidance, I’m here to help! Sources: pkg/stats/monitor.go | agents/src/ipc/supervised_proc.ts | Deploy and scale agents on LiveKit Cloud | Deploying to custom environments | LiveKit Docs
t
My project is already deployed on livekit cloud, I deploy it using - lk agent deploy, Now I have egress too, for uploading the video and audio meeting room recording of both ai avatar and candidate to s3 then I have extensive info loggings for each code line. Let me know now, what can I do ? or if you need more information, you can ask me too
t
I'd love to help you optimize memory usage for your LiveKit Cloud deployment! To get a clearer picture, could you share a bit more about: • The types of egress operations you're running (like room composite, track composite, or individual track egress)? • Whether you've set up any memory limits or autoscaling for your egress service? • If adjusting the logging verbosity (such as changing log levels) might be something you're open to? With these details, I’ll be better equipped to suggest the best configurations or tweaks for your setup. Looking forward to your response! Sources: Self-hosting the Egress Service | LiveKit docs | egress-sample.yaml | pkg/config/service.go | CHANGELOG.md | livekit-agents/livekit/agents/ipc/supervised_proc.py
t
1. Egress Operations: • Primary: Room composite egress via RoomCompositeEgressRequest with H264_720P_30 preset • Supporting MP4 file outputs to S3 • Both audio and video (audio_only=False) • No track composite operations currently implemented 2. Memory Limits/Autoscaling: • No explicit memory limits or autoscaling configurations found in the code • The egress service is using default LiveKit configurations 3. Logging Verbosity: • Current implementation has very verbose logging with extensive use of logger.info() • Multiple debug markers (🔍, 📊, ✅, etc.) Heres the answer for this
t
Thank you for sharing your setup! I’ve put together some tailored recommendations to help you optimize memory usage for your LiveKit Cloud deployment: 1. Egress Operations: ◦ Room composite egress with the H264_720P_30 preset can be quite resource-intensive. It’s a good idea to make sure your egress service has enough resources — for example, at least 4 CPUs and 4GB RAM per instance. ◦ Also, configuring the
max_memory
parameter in your egress service can help set a memory usage cap, which prevents any unexpected spikes. 1. Memory Limits/Autoscaling: ◦ Enabling autoscaling is a great way to dynamically manage resource usage. Here’s an example configuration: ◦ Additionally, setting explicit memory limits in your deployment can provide more control. For example: 1. Logging Verbosity: ◦ To reduce memory usage from logging, consider lowering the log level to
warn
or
error
instead of
info
. Here’s how you can do that: ◦ Using log sampling can also help reduce the volume of logs generated, which is another helpful step. I hope these suggestions make managing memory a bit easier for you! If you’d like, I’m here to help walk you through implementing any of these changes or answer any questions you might have.
t
but can you tell, how can I implement auto scaling, and how to know the memory ram and all, if my project is deployed on livekit cloud
t
I'm happy to share that LiveKit Cloud takes care of autoscaling for your deployed project automatically. The platform smartly adjusts resources based on demand, creating new instances and directing traffic to them as existing servers get busy. This means you don’t have to worry about setting up autoscaling policies yourself. To keep an eye on memory usage and other performance details: • You can check out the LiveKit Cloud dashboard, where you'll find useful metrics like CPU and memory usage, uptime, and session start latency for each agent deployment. • Alternatively, the
lk
CLI is great for real-time metrics and logs. For instance, running
lk agent list
shows you current CPU and memory usage, replica counts, and the status of your deployments. If you'd like, I’m here to help you navigate the dashboard or guide you through using the CLI commands—just let me know! Sources: Deploy and scale agents on LiveKit Cloud | server-sample.yaml | CLI Tools & Token Management | livekit/livekit_composite | DeepWiki | Deploying to production | LiveKit Docs
t
yes pleas3
t
I'd love to help you keep an eye on your memory usage and set up autoscaling for your LiveKit Cloud deployment. Here's a simple guide to get you started: • Accessing the LiveKit Cloud Dashboard: ◦ Just head over to https://cloud.livekit.io to open up the dashboard. ◦ Then, go to the Agents dashboard at https://cloud.livekit.io/projects/p_/agents where you can see real-time memory usage, CPU usage, and other important metrics for your deployed agents. • Using the
lk
CLI:
◦ Authenticate: Simply run
lk cloud auth
to log in and connect your project to the CLI. ◦ Set Default Project: Use
lk project set-default "<project-name>"
to make your commands easier to manage. ◦ Stream Logs: You can check runtime logs for memory-related insights by running
lk agent logs --id <agent-id> --log-type deploy
. Just a quick note: the CLI doesn’t show memory metrics directly, so for real-time memory monitoring, the LiveKit Cloud dashboard is your best friend. If you have any questions or need a hand navigating the dashboard or using the CLI commands, please don't hesitate to reach out—I’m here to help! Sources: README.md | Deploying to production | LiveKit Docs | CLI Tools & Token Management | livekit/livekit_composite | DeepWiki | Log collection | LiveKit Docs