Repository navigation
Description
I was computing the length of a Dask DataFrame which contains many (i.e. several thousand) partitions and is stored in Parquet format on S3. Something that looks like:
import dask.dataframe as dd
df = dd.read_parquet("s3://...", ...) # df has thousands of partitions
len(df)Shortly after this computation was kicked off, I got the following error (the full traceback is further down):
ClientError: An error occurred (SlowDown) when calling the ListObjectsV2 operation (reached max retries: 4): Please reduce your request rate.My guess is that since our len(df) implementation triggers lots of small, fast length computations, we're able to crank through many tasks quickly and hit some S3 rate limit.
This error message tells me to Please reduce your request rate. and I'm wondering how I can go about doing this. Perhaps there is some exponential backoff behavior I can trigger in s3fs to make api requests at an increasingly slower rate? Maybe there's other throttling mechanism I can use to prevent hitting these types of S3 limits?
Full traceback:
---------------------------------------------------------------------------
ClientError Traceback (most recent call last)
/opt/conda/envs/coiled/lib/python3.9/site-packages/s3fs/core.py in _call_s3()
/opt/conda/envs/coiled/lib/python3.9/site-packages/aiobotocore/client.py in _make_api_call()
ClientError: An error occurred (SlowDown) when calling the ListObjectsV2 operation (reached max retries: 4): Please reduce your request rate.
The above exception was the direct cause of the following exception:
OSError Traceback (most recent call last)
<timed eval> in <module>
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/dask/dataframe/core.py in __len__(self)
3942 return super().__len__()
3943 else:
-> 3944 return len(s)
3945
3946 def __contains__(self, key):
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/dask/dataframe/core.py in __len__(self)
579
580 def __len__(self):
--> 581 return self.reduction(
582 len, np.sum, token="len", meta=int, split_every=False
583 ).compute()
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/dask/base.py in compute(self, **kwargs)
284 dask.base.compute
285 """
--> 286 (result,) = compute(self, traverse=False, **kwargs)
287 return result
288
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/dask/base.py in compute(*args, **kwargs)
566 postcomputes.append(x.__dask_postcompute__())
567
--> 568 results = schedule(dsk, keys, **kwargs)
569 return repack([f(r, *a) for r, (f, a) in zip(results, postcomputes)])
570
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/distributed/client.py in get(self, dsk, keys, workers, allow_other_workers, resources, sync, asynchronous, direct, retries, priority, fifo_timeout, actors, **kwargs)
2746 should_rejoin = False
2747 try:
-> 2748 results = self.gather(packed, asynchronous=asynchronous, direct=direct)
2749 finally:
2750 for f in futures.values():
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/distributed/client.py in gather(self, futures, errors, direct, asynchronous)
2023 else:
2024 local_worker = None
-> 2025 return self.sync(
2026 self._gather,
2027 futures,
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/distributed/client.py in sync(self, func, asynchronous, callback_timeout, *args, **kwargs)
864 return future
865 else:
--> 866 return sync(
867 self.loop, func, *args, callback_timeout=callback_timeout, **kwargs
868 )
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/distributed/utils.py in sync(loop, func, callback_timeout, *args, **kwargs)
324 if error[0]:
325 typ, exc, tb = error[0]
--> 326 raise exc.with_traceback(tb)
327 else:
328 return result[0]
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/distributed/utils.py in f()
307 if callback_timeout is not None:
308 future = asyncio.wait_for(future, callback_timeout)
--> 309 result[0] = yield future
310 except Exception:
311 error[0] = sys.exc_info()
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/tornado/gen.py in run(self)
760
761 try:
--> 762 value = future.result()
763 except Exception:
764 exc_info = sys.exc_info()
~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/distributed/client.py in _gather(self, futures, errors, direct, local_worker)
1888 exc = CancelledError(key)
1889 else:
-> 1890 raise exception.with_traceback(traceback)
1891 raise exc
1892 if errors == "skip":
/opt/conda/envs/coiled/lib/python3.9/site-packages/dask/optimization.py in __call__()
/opt/conda/envs/coiled/lib/python3.9/site-packages/dask/core.py in get()
/opt/conda/envs/coiled/lib/python3.9/site-packages/dask/core.py in _execute_task()
/opt/conda/envs/coiled/lib/python3.9/site-packages/dask/core.py in <genexpr>()
/opt/conda/envs/coiled/lib/python3.9/site-packages/dask/core.py in _execute_task()
/opt/conda/envs/coiled/lib/python3.9/site-packages/dask/dataframe/io/parquet/core.py in __call__()
/opt/conda/envs/coiled/lib/python3.9/site-packages/dask/dataframe/io/parquet/core.py in read_parquet_part()
/opt/conda/envs/coiled/lib/python3.9/site-packages/dask/dataframe/io/parquet/core.py in <listcomp>()
/opt/conda/envs/coiled/lib/python3.9/site-packages/dask/dataframe/io/parquet/fastparquet.py in read_partition()
/opt/conda/envs/coiled/lib/python3.9/site-packages/fastparquet/api.py in to_pandas()
/opt/conda/envs/coiled/lib/python3.9/site-packages/fastparquet/api.py in read_row_group_file()
/opt/conda/envs/coiled/lib/python3.9/site-packages/fsspec/spec.py in open()
/opt/conda/envs/coiled/lib/python3.9/site-packages/s3fs/core.py in _open()
/opt/conda/envs/coiled/lib/python3.9/site-packages/s3fs/core.py in __init__()
/opt/conda/envs/coiled/lib/python3.9/site-packages/fsspec/spec.py in __init__()
/opt/conda/envs/coiled/lib/python3.9/site-packages/fsspec/asyn.py in wrapper()
/opt/conda/envs/coiled/lib/python3.9/site-packages/fsspec/asyn.py in sync()
/opt/conda/envs/coiled/lib/python3.9/site-packages/fsspec/asyn.py in _runner()
/opt/conda/envs/coiled/lib/python3.9/site-packages/s3fs/core.py in _info()
/opt/conda/envs/coiled/lib/python3.9/site-packages/s3fs/core.py in _simple_info()
/opt/conda/envs/coiled/lib/python3.9/site-packages/s3fs/core.py in _call_s3()
OSError: [Errno 16] Please reduce your request rate.
Activity
fjetter commentedon Aug 13, 2021
I do not quite understand where the issue is raised but the ListObjectsV2 is an operation which lists all blobs in a given container. This is an operation which is relatively expensive on S3/ABS/GCS and can be a significant slow down for very large datasets (>>100k files)
Depending on how the API is actually called, the scaling is dependent on the size of the dataset, or if multiple datasets are in a given container/bucket, even the number of objects in a container.
To circumvent this problem we created kartothek back in the days. There are other alternatives like Delta Lakes (Databricks) or Apache Iceberg (originally by Netflix) which all deal with this problem by, well, not listing blobs :) but rather remembering them all in a DB and/or file. I would've suspected that we do not require to list the blobs if used with the
_metadatafile but I haven't followed that development closelyIf the above is true, you should get that error during graph creation already, not when calling
lenmartindurant commentedon Aug 16, 2021
Indeed, the purpose of a _metadata file is not to have to list and read the metadata from many files. Where it's practical, it can save a lot of time, as well as circumvent API rate limits. If it is not present, you need to know what files to read from.
Some digging (even a traceback) would help us identify why there are many list calls. I can't even be sure if this is in the client or a worker.
I would have thought that it should be a single call to
s3.find(), which still need to paginate the output, but should count as a single list call.One interesting thing about parquet, is that the metadata of each file is stored int he footer; so you need to know the file size in order to find and read it. That size can be found via a list call (even with maxKeys=1) or head call; different users may have permissions to do one or the other of these.
Currently, the retry logic has a wait time of
min(1.7 ** i * 0.1, 15)(whereiis the trial number). As a user, you can increase the number of retries, but not change this expression.mrocklin commentedon Aug 17, 2021
I missed it the first time reading through the issue, but it looks like there is a traceback in the original post as a
<details>tag.martindurant commentedon Aug 17, 2021
There are a few S3-specific details that concern this issue. First I'll write some description of the situation.
open(), so that we can random-access read; indeed, parquet specifically needs the file footer for reading metadata (bytes [-8:-4] say how big the footer is). In the specific case here, I believe it was in the data reading phase.Now to possible amelioration:
retriesis currently a class attribute of S3FileSystem, not available as a constructor kwarg.ls, just once at graph creation time. We probably already did this in the client, if there is no _metadata file. I am not totally sure how to get the size into the file object across all possible storage backends.catmethod allows this, and this method is now used in some cases by fastparquet.cat, again) and process them in memory. This may even be more performant, depending on how the original access pattern used the bytes cache, but perhaps wasteful on memory.@rjzamora : the last three points above are potentially interesting parquet optimisations.
martindurant commentedon Aug 19, 2021
@jrbourbeau , can you see if setting
S3FileSystem.retries = 10(in the client and workers too) avoids this problem?jrbourbeau commentedon Aug 24, 2021
Setting
s3fs.S3FileSystem.retries = 10(both on the cluster workers and my client Python session) didn't have an impact on rate errors being raised. However, adding Dask retriesdid help
quasiben commentedon Sep 2, 2021
Pinterest engineering is also currently engaged with s3/parquet improved reading:
https://medium.com/pinterest-engineering/improving-efficiency-and-reducing-runtime-using-s3-read-optimization-b31da4b60fa0
ian-r-rose commentedon May 4, 2022
In fsspec/s3fs#620 we added some strategies to avoid rate limiting and to retry when it comes up. I'm unable to reproduce anything like the described behavior using s3fs
mainright now. I suggest we close this until/unless it crops up again. What you do think @jrbourbeau?jrbourbeau commentedon May 5, 2022
Sounds good, thanks for the upstream improvement @ian-r-rose