Dask delayed performance issues

Viewed 8

I'm relatively new to Dask. I'm trying to parallelize a "custom" function that doesn't use Dask containers. I would just like to speed up the computation. But my results are that when I try parallelizing with dask.delayed, it has significantly worse performance than running the serial version. Here is a minimal implementation demonstrating the issue (the code I actually want to do this with is significantly more involved :) )

import dask,time

def mysum(rng):
    # CPU intensive
    z = 0
    for i in rng:
        z += i
    return z

# serial
b = time.time(); zz = mysum(range(1, 1_000_000_000)); t = time.time() - b
print(f'time to run in serial {t}')
# parallel
ms_parallel = dask.delayed(mysum)
ss = []
ncores = 10
m = 100_000_000
for i in range(ncores):
    lower = m*i
    upper = (i+1) * m
    r = range(lower, upper)
    s = ms_parallel(r)
    ss.append(s)

j = dask.delayed(ss)
b = time.time(); yy = j.compute(); t = time.time() - b
print(f'time to run in parallel {t}')

Typical results are:

time to run in serial 55.682398080825806
time to run in parallel 135.2043571472168

It seems I'm missing something basic here.

0 Answers
Related