Skip to content

S3 rate limit encountered during DataFrame computation #8026

Closed

Description

@jrbourbeau

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?

cc @martindurant

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

  1. fjetter commented on Aug 13, 2021

    @fjetter
    Member

    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 _metadata file but I haven't followed that development closely

    If the above is true, you should get that error during graph creation already, not when calling len

  2. martindurant commented on Aug 16, 2021

    @martindurant
    Member

    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) (where i is the trial number). As a user, you can increase the number of retries, but not change this expression.

  3. mrocklin commented on Aug 17, 2021

    @mrocklin
    Member

    Some digging (even a traceback) would help us identify why there are many list calls

    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.

  4. martindurant commented on Aug 17, 2021

    @martindurant
    Member

    There are a few S3-specific details that concern this issue. First I'll write some description of the situation.

    • Currently, s3fs uses list_objects_v2 to get the info on a file (size, Etag, etc.).
    • We need the file size during a call to 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.
    • The file size could be found via a call to head_object rather than list_objects_v2 with the advantage that it would list versions and disadvantage that it would not work for (virtual) directories and is much slower. We only use head_object for buckets marked as versioned. Note that it has its own rate limit and users may have separate permissions to list, head and get data.

    Now to possible amelioration:

    • the number of retries and exponential backoff factor can be changed; this obviously means than some truly problematic calls will take longer to fail. retries is currently a class attribute of S3FileSystem, not available as a constructor kwarg.
    • use dask retries in addition to S3 retries
    • supply the file size via a previous call to 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.
    • the parquet engine could be made to fetch the "last X bytes" from a key without first checking the size for metadata. The filesystem cat method allows this, and this method is now used in some cases by fastparquet.
    • the parquet engine could read all the bytes of a given row-group or chunk (using 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.

  5. martindurant commented on Aug 19, 2021

    @martindurant
    Member

    @jrbourbeau , can you see if setting S3FileSystem.retries = 10 (in the client and workers too) avoids this problem?

  6. jrbourbeau commented on Aug 24, 2021

    @jrbourbeau
    MemberAuthor

    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 retries

    with dask.annotate(retries=10):
        len(df)

    did help

  7. quasiben commented on Sep 2, 2021

    @quasiben
    Member
  8. ian-r-rose commented on May 4, 2022

    @ian-r-rose
    Collaborator

    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 main right now. I suggest we close this until/unless it crops up again. What you do think @jrbourbeau?

  9. jrbourbeau commented on May 5, 2022

    @jrbourbeau
    MemberAuthor

    Sounds good, thanks for the upstream improvement @ian-r-rose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions