Memory release after Parallel
See original GitHub issueI did a test and found objects returned by parallel processing cannot be del and thus memory cannot be released. simplified code:
### Measure memory usage
import psutil, gc
ps = psutil.Process()
def memory_usage_psutil(ps):
gc.collect()
return ps.get_memory_info().rss / (2 ** 20)
### a function making a list from 0 to 10**6
def make_list(i): return [x for x in xrange(10 ** 6)]
print 'start', memory_usage_psutil()
### create 5 such lists w/o parallel and delete
single = [make_list(i) for i in range(5)]
print 'have single list', memory_usage_psutil()
del single
print 'delete single list', memory_usage_psutil()
### create 5 such lists with parallel and delete
parallel = Parallel(n_jobs=5)(delayed(make_list)(i) for i in range(5))
print 'have parallel list', memory_usage_psutil()
del parallel
print 'delete parallel list', memory_usage_psutil()
### =========Output==========
start 19.1796875
have single list 174.328125
delete single list 19.3203125
have parallel list 194.50390625
delete parallel list 154.9609375
Issue Analytics
- State:
- Created 9 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
is there a way to release the memory when do parallel ...
Anyhow, I tried to figure which is the possible memory leak in your code dividing it into the three functions or possibilities you...
Read more >Memory release after joblib.Parallel [python]
Stuck with the issue with memory consumption - after running joblib's Parallel, deleting results and gc.collect() -ing I still have ...
Read more >RAM keep increasing until crash when run many brms/Stan ...
So I try to use furrr package to run these models in parallel. Everything is good, but the RAM keep increasing until R...
Read more >Parallel.For memory leaks? - MSDN - Microsoft
I have a cache which clones cached objects before returning them. The sequential code I had is: for (int i = 0; i...
Read more >How Fork Join Pool caused Memory Leak!!
I'm one of those person who is crazy about parallel streams and functional programming ,before I faced this memory leak I always thought ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue should be resolved in the latest version of
joblib
which feature memory leaks safeguards with theloky
backend:psutil
is installed on the system, a worker process is shutdown and a new worker is re-spawn if its memory usage grows by more than 100Mb between two tasks (the checks are performed at most once every second).gc.collect
periodically between 2 tasks.Please try to use
joblib==0.12.4
and report if you still see some memory leaked.I went back to old versions of joblib 0.8.4. And I cannot reproduce the bug either. It might have been fixed on the Python side (I am using Python 3.7) and is therefore unrelated to joblib as Gael initially suggested…