在 Dask 中预分散数据对象有优势吗?
Is there an advantage to pre-scattering data objects in Dask?
如果我将一个数据对象预先分散到各个工作节点,它会被完整地复制到每个工作节点吗?如果该数据对象很大,这样做有优势吗?
以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()
函数到activity反映在dashboard上,有很长的延迟,我怀疑是这样是由于数据复制。
预打散是为了避免将大对象数据放入任务图中。
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
到 return 会很慢,Dask 甚至可能会发出警告。
所以我们分散我们的数据,在 return
中接收未来
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
在你的情况下你几乎这样做,唯一的区别是你分散你的数据,然后忘记它的未来 returns,然后发送又是你的数据。
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
或不。如果您知道您的所有员工都需要这些数据,那么这样做并不是一件坏事,但无论如何都会好起来的。
如果我将一个数据对象预先分散到各个工作节点,它会被完整地复制到每个工作节点吗?如果该数据对象很大,这样做有优势吗?
以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()
函数到activity反映在dashboard上,有很长的延迟,我怀疑是这样是由于数据复制。
预打散是为了避免将大对象数据放入任务图中。
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
到 return 会很慢,Dask 甚至可能会发出警告。
所以我们分散我们的数据,在 return
中接收未来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
在你的情况下你几乎这样做,唯一的区别是你分散你的数据,然后忘记它的未来 returns,然后发送又是你的数据。
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
或不。如果您知道您的所有员工都需要这些数据,那么这样做并不是一件坏事,但无论如何都会好起来的。