Repository navigation
Open
Description
What happened: When using shuffle = 'disk' merging took 50 minutes compared to 2 minutes when using shuffle = 'tasks'. Also, Dask dashboard was showing very low CPU utilization when using shuffle = 'disk'.
What you expected to happen: I expected merging with shuffle = 'disk' to be faster than merging with shuffle = 'tasks' since the load on the scheduler is supposed to be lower in that case.
Minimal Complete Verifiable Example:
from dask.distributed import Client
import dask.dataframe as dd
import pandas as pd
import numpy as np
import os
from time import time
import pandas.util.testing
import dask.config
# folder in which data will be saved
data_folder = 'path_to_folder_for_saving_data'
# enable shuffle compression
# NOTE: you need to install python-snappy package in order to use Snappy compression!!
dask.config.set({
"dataframe.shuffle-compression": 'Snappy',
'temporary_directory': data_folder
})
# start a local Dask cluster
# (note: I used a single machine with 14 cores and started the cluster with n_workers=14 and threads_per_worker=1)
client = Client(local_directory=data_folder )
# create the folder for fake data for the right side of the merge
os.mkdir('%s/right_ddf' % data_folder)
# number of partitions for the right side of the merge
N_partitions_right = 40
# number of rows per partition
Nrows_right = 1038790
# create data for the right side of the merge
for partition_id in range(N_partitions_right):
df = pd.DataFrame({'ID':pandas.util.testing.rands_array(16, Nrows_right, dtype='O'),
'Date':pd.Timestamp('2019-12-01')})
df.to_parquet('%s/right_ddf/%d.parquet' % (data_folder, partition_id))
# create the folder for fake data for the left side of the merge
os.mkdir('%s/left_ddf' % data_folder)
# number of partitions for the left side of the merge
N_partitions_left = 1325
# number of rows per partition
Nrows_left = 99063
# to create the left side of the merge, sample Nrows_left from a randomly
# selected partion on the right side
partitions_to_sample = np.random.randint(0, high=(N_partitions_right-1), size=N_partitions_left)
for partition_id, partition_to_load in enumerate(partitions_to_sample):
df = pd.read_parquet('%s/right_ddf/%d.parquet' % (data_folder, partition_to_load))
df = df.sample(Nrows_left, replace=True)
df.to_parquet('%s/left_ddf/%d.parquet' % (data_folder, partition_id))
# benchmark merging using tasks and disk shuffle
for shuffle_type in ['tasks', 'disk']:
# load data
left_ddf = dd.read_parquet('%s/left_ddf' % data_folder)
right_ddf = dd.read_parquet('%s/right_ddf' % data_folder)
# merge
left_ddf = left_ddf.merge(right_ddf, on='ID', how='inner', shuffle=shuffle_type)
t0 = time()
left_ddf = left_ddf.persist().head()
elapsed_time = (time() - t0)/60.
print('Merging using %s takes %.1f minutes' % (shuffle_type, elapsed_time))EDIT: If the above MVE is too much for your machine, use Nrows_right = 1038, Nrows_left = 99, and N_partitions_left = 600. Merging with shuffle='tasks' then takes 0.4 min, and merging with shuffle='disk' takes 2.4 minutes, or a factor of 6 difference (with n_workers=14 and threads_per_worker=1).
Environment:
- Dask version: 2021.11.2
- Python version: 3.8.12
- Operating System: Windows Server 2016 64 bits
- Install method (conda, pip, source): conda
Metadata
Metadata
Assignees
Labels
No labels
Activity
fjetter commentedon Dec 2, 2021
Thanks for this example. I'm currently trying to reproduce but a few notes up front
left_ddf = left_ddf.repartition(npartitions=40)(40 is kind of random, you might even be better of with a smaller value since htere are fewer rows left)bsesar commentedon Dec 3, 2021
Thank you for the comments, @fjetter. My answers are below:
shuffle='tasks'does not seem to have a problem with them (i.e., merging takes about 2 minutes in that case). That being said, reducing the number of partitions in the left dataframe by half does reduce the merging time in half. So it seems thatshuffle='disk'is quite sensitive to the number of dataframes, whileshuffle='tasks'is not as sensitive (or is just too fast to not make any notable difference).Nrows_right = 1038,Nrows_left = 99, andN_partitions_left = 600in the MVE code. Merging withshuffle='tasks'takes 0.4 min, and merging withshuffle='disk'takes 2.4 minutes, or a factor of 6 difference.In the end, my point is that on the same machine with the same data and disk, merging with
shuffle='tasks'is much faster than merging withshuffle='disk'.fjetter commentedon Mar 17, 2025
This is already an old issue but the issue still persists. The below configuration is running the shuffle operations on a VM that should be able to fit the dataset twice
this is a 4 vCPU VM and we can see that the initial burst uses all CPUs which is the tasks based shuffle. The endless tail is the disk
Allowing this to finish gives something like
{'tasks': 94.88317428799999, 'disk': 2241.7395113889997}i.e. I can reproduce a ~24x slowdown of disk compared to tasks with a very simple example
fjetter commentedon Mar 17, 2025
From the metrics it also looks like it is only able to use a single CPU when doing the disk based shuffle.
some brief profiling points to https://github.com/fjetter/dask/blob/33412e9f1dfe7d0b3408d495fc0a00dbce60bdcf/dask/dataframe/dask_expr/_shuffle.py#L506 which eats >60% of this runtime and primarily points to pyarrow.compute, probably due to the pyarrow string dtype. I don't know what the tasks based approach is doing that makes this so much faster