Does agent join the room or not depends on the Mem...
# ask-ai
c
Does agent join the room or not depends on the Memory usage of the app ? I see in the sample app the memory usage in below 500 MB so it works well there, but in our react native expo app it's above 500MB so agent never joins and also the screen hangs with warnings(process memory usage is high).
t
Thanks for reaching out, Shwet. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I completely understand how frustrating it can be when high memory usage stops agents from joining a room in LiveKit. This issue might be happening due to memory limits either on your React Native Expo app or on the server side where the agent processes run. Let’s walk through some helpful steps to troubleshoot and optimize your setup: • Check Agent Server Resources: It’s important to make sure your agent server has enough memory—ideally at least 8GB. Also, keep an eye on the agent process logs for any memory-related errors. • Client-Side Diagnostics: Try monitoring your app’s memory usage with development tools. Make sure your WebRTC setup includes
registerGlobals()
and that you’re using Expo development builds instead of Expo Go. • Connection State Monitoring: Adding proper connection state monitoring in your app can help gracefully handle connection failures and implement retry logic. • Memory Optimization: Take a look at which LiveKit components you’re using, like STT or TTS, and consider turning off enhanced features such as noise cancellation if they’re not essential. To better assist you, could you please share a bit more info? • What memory usage levels are you seeing in your React Native app? • Are there any specific error messages when the agent can’t join? • Which agent components (like STT, TTS) are you currently using? • Are your agents running on your own infrastructure or LiveKit Cloud? • Can you confirm your Expo app is using development builds rather than Expo Go? Once I have this information, I’ll be in a much better position to help you find the right solution. Looking forward to your reply! Sources: Deploying to custom environments | LiveKit Docs | pkg/stats/monitor.go | agents/CHANGELOG.md | livekit-agents/livekit/agents/ipc/supervised_proc.py | docs/functions/LiveKitRoom.html
c
• What memory usage levels are you seeing in your React Native app? -> Between 500MB - 1GB • Are there any specific error messages when the agent can’t join? -> process memory usage is high • Are your agents running on your own infrastructure or LiveKit Cloud? -> LiveKit Cloud • Can you confirm your Expo app is using development builds rather than Expo Go? -> yes
t
Thank you so much for sharing these details with me. I understand how frustrating memory usage issues and connection errors can be, so let’s work through this together. Based on the memory usage levels you mentioned (500MB - 1GB) and the error about high process memory usage, here are some thoughtful recommendations to help optimize your React Native Expo app and get your agent connection running smoothly: • Audio Session Management: It’s important to manage your audio sessions carefully. Try using the
AudioSession
class to start and stop sessions as needed — this can really help reduce memory overhead. • Adaptive Streaming: Consider configuring adaptive streaming to better match your device's capabilities. For instance, using screen pixel density can help handle different screen resolutions more efficiently. • Background Processing: For Android, setting up a foreground service can keep connections alive in the background. On iOS, make sure to enable the
audio
and
voip
background modes in your XCode project. • Track Management: Cleaning up unused tracks when components unmount is a great way to free up memory. Hooks like
useTracks
can assist with efficient track rendering. • Development Build: Double-check that you’re using development builds created with
expo-dev-client
, since LiveKit isn’t compatible with Expo Go. Also, since you’re using LiveKit Cloud, it’s a good idea to ensure your agent server has enough memory resources—ideally at least 8GB—to handle the workload comfortably. Could you please let me know if these suggestions help with the issue? If you’re still seeing problems, feel free to share any specific memory-related symptoms like app crashes, slow performance, or connection drops. Also, letting me know if this happens on both iOS and Android or just one platform will really help me guide you better. Sources: Expo quickstart | LiveKit Docs | README.md | Deploying to custom environments | LiveKit Docs | README.md | Web and mobile frontends | LiveKit Docs
c
Anything to do with job_memory_warn_mb and job_memory_limit_mb ? Although our agent is working in sample app and not in our own app, so I'm not sure
t
I’d love to help you understand how the parameters
job_memory_warn_mb
and
job_memory_limit_mb
work in LiveKit to keep an eye on memory usage for each job process: • `job_memory_warn_mb`: This sets a memory warning threshold (default is 500 MB). If a job process goes over this limit, a friendly warning is logged, but the process keeps running smoothly. • `job_memory_limit_mb`: This defines the maximum memory a job can use (default is 0, meaning no limit). If a job exceeds this, it’s stopped to avoid hogging too many resources. These settings are part of LiveKit’s process isolation model, which means if one job uses too much memory and gets stopped, it won’t impact the other agents you have running. This is especially helpful when working with memory-heavy tasks like audio processing or AI model inference. Since your agent works perfectly in the sample app but not in your own, it might be that your app’s memory use is going beyond these limits. You can easily tweak these parameters in your agent configuration to better fit your app’s needs. For example:
Copy code
from livekit.agents import WorkerOptions

opts = WorkerOptions(
    entrypoint_fnc=your_agent_function,
    job_memory_warn_mb=750,    # Log warnings at 750 MB
    job_memory_limit_mb=1024,  # Kill process at 1 GB
)
If you’d like, I’m here to guide you through adjusting these settings in your environment—just let me know! Sources: livekit-agents/livekit/agents/ipc/proc_pool.py
c
so if the default job_memory_limit_mb in 0 then why the agent is not joining in our app. It just hang the app completely while attempting to join the room
t
Thank you for sharing the details! Setting
job_memory_limit_mb
to 0 does disable the memory limit, so it typically shouldn’t cause the agent to hang directly. That said, I understand how frustrating this hanging issue can be, and it might be connected to other parts of the agent lifecycle or the memory monitoring system. Let’s explore a few areas that could be worth checking: • Process Initialization Timing: Sometimes, even with the limit disabled, the memory monitoring system might still affect initialization. • Executor Type: If you’re using something other than a process-based executor, the memory limit setting might lead to unexpected behavior. • Resource Allocation: The memory monitoring infrastructure could still be active and influencing resource availability. To help you further, could you please share a bit more info? • What type of job executor are you using (process or thread)? • Are there any specific error messages or logs when the hanging happens? • Does the hanging occur every time or only in certain situations? • What happens if you try setting
job_memory_limit_mb
to a positive number instead of 0? • Are there any other configuration differences between the sample app that works and your app? • At which exact point does the hanging occur? For example, during worker registration, job acceptance, or room connection? Once I have these details, I’ll be in a better position to help you identify the root cause and suggest some targeted solutions. I’m here to support you every step of the way! Sources: livekit-agents/livekit/agents/ipc/job_proc_lazy_main.py