Python multiprocessing: why are large chunksizes slower?

前端 未结 1 1354
[愿得一人]
[愿得一人] 2020-12-30 10:36

I\'ve been profiling some code using Python\'s multiprocessing module (the \'job\' function just squares the number).

data = range(100000000)
n=4
time1 = tim         


        
相关标签:
1条回答
  • 2020-12-30 10:55

    About optimal chunksize:

    1. Having tons of small chunks would allow the 4 different workers to distribute the load more efficiently, thus smaller chunks would be desirable.
    2. In the other hand, context changes related to processes add an overhead everytime a new chunk has to be processed, so less amount of context changes and therefore less chunks are desirable.

    As both rules want different aproaches, a point in the middle is the way to go, similar to a supply-demand chart.

    0 讨论(0)
提交回复
热议问题