-
Notifications
You must be signed in to change notification settings - Fork 217
My Project Is Running Out of Memory
How can you tell if your project is running out of memory?
-
Use
top
in a terminal. Currently the easiest way to test this is to open a terminal (+New --> Terminal) in your project, then typetop
. Watch the processes listed there, especially the column labeledRES
, which stands for "resident memory". If your project has 1000MB of RAM, which is the default in CoCalc, and the sum of the RES entries is close to 1000000, then you should definitely expect a memory allocation failure soon.You can type
M
into top to make it sort processes by memory, which will help in seeing how much is used. You can also hit the space bar a lot to make it update frequently. Typeq
when you are done. If you want to kill a process in top, typek
then the process id (PID), which is in the first column. -
Project settings. You can also look in the Settings (wrench) tab of your project under "Shared RAM", which will say how much is "currently" used. This is only updated once every 30s though, and may not show spikes in attempted memory allocation.
-
Use
smem -ntk
in a terminal. This command gives a useful breakdown of memory usage.
You may be able to work around a low-memory situation temporarily by killing selected processes or restarting your project.
But if you're hitting memory issues and just want more space, upgrade your project. The subscription are listed here. For example, for $7/month, you can upgrade from 1GB to 4GB, and have a lot more elbow room! If you're confused or have questions about upgrading, just ask at [email protected].
When you produce many graphics in a row and use the usual pyplot API, the intermediate graphics are not cleaned up. Run the following to clear up the memory:
import matplotlib.pyplot as plt
plt.close('all')
In case you're using rstan in R, you can try to switch the C++ compiler to clang++. Run the following in a cell to create appropriate config files in your project:
dir.create("~/.R", showWarnings = FALSE)
cat("CXX = clang++", "CXXFLAGS = -g0 -Os -march=native -mtune=native", file = "~/.R/Makevars", sep = "\n")
Sys.setenv(R_MAKEVARS_USER = normalizePath("~/.R/Makevars"))
Credits: https://github.com/sagemathinc/cocalc/issues/2337#issuecomment-355637033 by @bgoodri
This Wiki is for CoCalc.com.
A more structured documentation is the CoCalc User Manual.
For further questions, please contact us.