I am having problems with memory usage and I would like to make sure that my program, which is meant to run several programs, releases memory as soon as possible. For this I am using something like:
with cf.ProcessPoolExecutor(max_workers=1) as executor:
executor.submit(fun)
such that all the memory used by fun is released to be used by the next function. Is this the best approach? Are multiprocessing or suprocess a better way?
Thank you for your reply. The thing is that I have tried memray and had a hard time understanding these flamegraphs and going from there to actually finding the root of the problem. I just ran memray and from what I see:
Computing clusters often have strict overcommit policies when multiple jobs are permitted to run on a single physical compute node. The OS generally can’t allow you to overcommit and still constrain your processes to stay within a memory limit.
If you’re using numpy, then the virtual memory usage from import numpy alone scales with the OMP_NUM_THREADS variable, which will default to the number of available cores if you don’t set it. Most of these pages never get loaded, so it’s more an accounting quirk than an actual problem on a development system, but it’s pretty rough on systems that don’t allow overcommitting.