question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory release after Parallel

See original GitHub issue

I 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:closed
  • Created 9 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
tomMoralcommented, Sep 6, 2018

This issue should be resolved in the latest version of joblib which feature memory leaks safeguards with the loky backend:

  • If 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).
  • else, we call gc.collect periodically between 2 tasks.

Please try to use joblib==0.12.4 and report if you still see some memory leaked.

0reactions
ogriselcommented, Sep 9, 2018

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…

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found