I am using multiprocessing.imap_unordered to perform a computation on a list of values:
def process_parallel(fnc, some_list):
pool = multiprocessing.Pool()
for result in pool.imap_unordered(fnc, some_list):
for x in result:
yield x
pool.terminate()
Each call to fnc returns a HUGE object as a result, by design. I can store N instances of such object in RAM, where N ~ cpu_count, but not much more (not hundreds).
Now, using this function takes up too much memory. The memory is entirely spent in the main process, not in the workers.
How does imap_unordered store the finished results? I mean the results that were already returned by workers but not yet returnedpassed on to user. I thought it was smart and only computed them "lazily" as needed, but apparently not.
It looks like since I cannot consume the results of process_parallel fast enough, the pool keeps queueing these huge objects from fnc somewhere, internally, and then blows up. Is there a way to avoid this? Limit its internal queue somehow?
I'm using Python2.7. Cheers.
I am using multiprocessing.imap_unordered to perform a computation on a list of values:
def process_parallel(fnc, some_list):
pool = multiprocessing.Pool()
for result in pool.imap_unordered(fnc, some_list):
for x in result:
yield x
pool.terminate()
Each call to fnc returns a HUGE object as a result, by design. I can store N instances of such object in RAM, where N ~ cpu_count, but not much more (not hundreds).
Now, using this function takes up too much memory. The memory is entirely spent in the main process, not in the workers.
How does imap_unordered store the finished results? I mean results that were already returned by workers but not yet returned to user. I thought it was smart and only computed them "lazily" as needed, but apparently not.
It looks like since I cannot consume the results of process_parallel fast enough, the pool keeps queueing these huge objects from fnc somewhere, internally, and then blows up. Is there a way to avoid this?
I'm using Python2.7. Cheers.
I am using multiprocessing.imap_unordered to perform a computation on a list of values:
def process_parallel(fnc, some_list):
pool = multiprocessing.Pool()
for result in pool.imap_unordered(fnc, some_list):
for x in result:
yield x
pool.terminate()
Each call to fnc returns a HUGE object as a result, by design. I can store N instances of such object in RAM, where N ~ cpu_count, but not much more (not hundreds).
Now, using this function takes up too much memory. The memory is entirely spent in the main process, not in the workers.
How does imap_unordered store the finished results? I mean the results that were already returned by workers but not yet passed on to user. I thought it was smart and only computed them "lazily" as needed, but apparently not.
It looks like since I cannot consume the results of process_parallel fast enough, the pool keeps queueing these huge objects from fnc somewhere, internally, and then blows up. Is there a way to avoid this? Limit its internal queue somehow?
I'm using Python2.7. Cheers.
Python's multiprocessing and memory
I am using multiprocessing.imap_unordered to perform a computation on a list of values:
def process_parallel(fnc, some_list):
pool = multiprocessing.Pool()
for result in pool.imap_unordered(fnc, some_list):
for x in result:
yield x
pool.terminate()
Each call to fnc returns a HUGE object as a result, by design. I can store N instances of such object in RAM, where N ~ cpu_count, but not much more (not hundreds).
Now, using this function takes up too much memory. The memory is entirely spent in the main process, not in the workers.
How does imap_unordered store the finished results? I mean results that were already returned by workers but not yet returned to user. I thought it was smart and only computed them "lazily" as needed, but apparently not.
It looks like since I cannot consume the results of process_parallel fast enough, the pool keeps queueing these huge objects from fnc somewhere, internally, and then blows up. Is there a way to avoid this?
I'm using Python2.7. Cheers.