Resources not cleaned correctly only on streamlit cloud

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 !!

Hi @shaokai_ye

Would it also help to profile your app to see which particular step may be consuming more resources than others and this can be performed using the streamlit-profiler component:

In provisioning a server there are several prerequisite processes that may be running in the background and each of which may be consuming resources. It may be helpful to establish a baseline on the resource consumption for a very basic app (e.g. a 1-line app with an import statement of Streamlit), which can then be compared to a working implementation of the finished app. The above profiling may also provide insights on the resource consumption of various code segments.

Hope this helps!

Best regards,
Chanin

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.