如果我将数据对象预分散到多个工作节点上,是否会将它完整地复制到每个工作节点上?如果该数据对象很大,这样做有好处吗?
以该futures
接口为例:
client.scatter(data, broadcast=True)
results = dict()
for i in tqdm_notebook(range(replicates)):
results[i] = client.submit(nn_train_func, data, **params)
以该delayed
接口为例:
client.scatter(data, broadcast=True)
results = dict()
for i in tqdm_notebook(range(replicates)):
results[i] = delayed(nn_train_func, data, **params)
我问的原因是因为我注意到以下现象:
delayed
似乎将数据重新发送到工作程序节点,从而使内存使用量大约增加了一倍。看来预分散并没有按照我的预期去做,这允许工作节点引用预分散的数据。futures
接口需要很长的时间来迭代通过循环(显著更长)。我目前不确定如何确定这里的瓶颈。delayed
接口,从compute()
调用函数的时间到活动在仪表板上反映的时间,存在很大的延迟,我怀疑这是由于数据复制造成的。预分散旨在避免将大对象数据放入任务图中。
x = np.array(lots_of_data)
a = client.submit(add, x, 1) # have to send all of x to the scheduler
b = client.submit(add, x, 2) # again
c = client.submit(add, x, 3) # and again
您会感到痛苦,因为client.submit
返回的速度很慢,Dask甚至会发出警告。
因此,我们分散了数据,获得了回报
x = np.array(lots_of_data)
x_future = client.scatter(x)
a = client.submit(add, x_future, 1) # Only have to send the future/pointer
b = client.submit(add, x_future, 2) # so this is fast
c = client.submit(add, x_future, 3) # and this
在您的情况下,您几乎会这样做,唯一的区别是您分散了数据,然后忘记了数据返回的未来,然后再次发送数据。
client.scatter(data, broadcast=True) # whoops! forgot to capture the output
data = client.scatter(data, broadcast=True) # data is now a future pointing to its remote value
您可以选择是否broadcast
。如果您知道所有工作人员都需要此数据,那么这并不是一件坏事,但是无论如何,一切都会好起来的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句