I have some strange behavior with Python Multiprocessing Pool performance. In the following code, data
is an ndarray of millions of images to be resized, and chunks_list
is chunks of data
. I use pool = Pool(14)
. The function resize_images
resizes a group of images at once, while resize_image
resizes a signle image.
The following code:
res = [pool.apply_async(resize_image, args=[img]).get() for img in data]
is faster than this code:
chunks_list = [data[i:i + chunk_size] for i in range(0, len(data), chunk_size)]
res = [pool.apply_async(resize_images, args=[imgs]).get() for imgs in chunks_list]
Why is that? I expected the opposite to be true, because the first code will assign many 'tiny' processes to the pool of CPU's. But chunks will produce less assignations. Is there more efficient way to achieve what I want? (GPU maybe?)