I have a private streamlit app I can’t share right now. But I would really appreciate it if someone knows the issue I run into:
Context:
I build my “database” as a dictionary inside st.session_state. The rational is that since every user has his own session object, every user has his own copy of database and once st.session_state is cleaned (refreshing or exiting), the user’s unique data would also be gone. I believe this should solve memory leak.
When I test my app locally, I ask it to log the process memory using psutil and memory_profiler in every rerun. I checked the logs and plots and it tells me there is no memory leak (as the RAM usage always goes back to a constant, low number even if I start multiple browser tabs to run tasks at the same time).
However, after I deploy the same code to the cloud, my logger tells me that the process memory never really drops and the memory usage is almost always around 1000 MB, resulting in a rather slow speed compared to the local app. Furthermore, it runs into resource limit quickly.
Update: actually, I don’t think it’s related to the cloud server. I can reproduce the same behavior using my own linux server. Somehow using my labtop (Mac) as server it knows how to clean the resource correctly. I am really confused.
I am quite stuck here. Please let me know if you have ideas. Thanks !!