Skip to content

Processing large remote Parquet datsets #8031

Closed

Description

@jrbourbeau

Recently I ran into some issues processing large Parquet datasets which were stored in S3 (with the code snippet below) and raised a few corresponding issues:

I'm wondering if others folks have run into other issues themselves. I'd like to use this issue to solicit and track issues related to processing large, remote Parquet datasets.

import pandas as pd
import dask
import dask.dataframe as dd
from dask.distributed import Client

# Use Coiled to create a large cluster.
# Though any Dask cluster would work just as well.
import coiled
cluster = coiled.Cluster(n_workers=200, worker_memory="16 GiB")
client = Client(cluster)

# Generate a large synthetic dataset and write it to S3
df = dask.datasets.timeseries(
    dtypes={str(i): int for i in range(1_000)},
    freq="1s",
    start="2000-01-01",
    end="2021-01-01",
)

storage_options={"config_kwargs": {"region_name": "us-east-1"}}
df.to_parquet(
    "s3://<bucket>/timeseries.parquet",
    engine="pyarrow-dataset",
    overwrite=True,
    storage_options=storage_options,
)

# Read in dataset and do some basic processing
df = dd.read_parquet(
    "s3://<bucket>/timeseries.parquet",
    engine="pyarrow-dataset",
    storage_options=storage_options,
)

def func(row: pd.Series) -> str:
    return f"{row[0]}-{row[1]}-{row[2]}"

df["new"] = df.apply(func, axis=1)

# Write processed dataset back to S3
df.to_parquet(
    "s3://<bucket>/timeseries-processed.parquet",
    engine="pyarrow-dataset",
    overwrite=True,
    storage_options=storage_options,
)

Activity

  1. avriiil commented on Aug 17, 2021

    @avriiil
    Contributor

    Not entirely sure this is related @jrbourbeau as your issues seem to do more with reading rather than writing parquet files. But thought I'd share anyway, feel free to LMK if it'd be more useful for me to post this elsewhere.

    I'm running into issues when writing larger datasets to parquet into a public S3 bucket with the code snippet below.

    tl;dr
    Small, dummy datasets work (see "This Works" section below) but larger timeseries dataframe (thousands of partitions) fails (see "This Fails" section) with a KilledWorker error. Writing to_csv works for both the small and the large datasets.

    IMPORTS AND SPINNING UP CLUSTER

    import coiled
    import dask.dataframe as dd
    from dask.distributed import Client
    import dask
    
    cluster = coiled.Cluster(
        name="data-import",
        software='rrpelgrim/create-coiled-datasets-m1-test',
        n_workers=20,
        worker_cpu=4,
        worker_memory='32Gb',
        scheduler_cpu=2,
        shutdown_on_close=False,
        scheduler_options={'idle_timeout':'1hour'},
    )
    
    client = Client(cluster)
    client
    

    THIS WORKS

    from pandas import DataFrame, to_datetime
    from dask.dataframe import from_pandas
    
    df = DataFrame({
         "index": ["1", "2", "3", "2", "3", "1", "4"],
         "date":  to_datetime(["2017-01-01", "2017-01-01", "2017-01-01", "2017-01-02", "2017-01-02", 
                                                "2017-01-06", "2017-01-09"]),
         "amount": [100, 200, 300, 400, 500, 600, 700]
        }
    )
    
    df = from_pandas(df, npartitions=2).set_index("index")
    
    df.to_parquet(
        "s3://path/to/bucket/small-dummy.parquet",
        engine='pyarrow',
        schema='infer'
    )
    

    THIS FAILS

    df2 = dask.datasets.timeseries("1950") # defaults to 18K partitions in my case 
    
    df2.to_parquet(
        "s3://path/to/bucket/large-dummy.parquet",
        engine='pyarrow',
        schema='infer'
    )
    

    I get a warning when I run the cell:

    /Users/rpelgrim/mambaforge/envs/create-coiled-datasets-m1/lib/python3.9/site-packages/distributed/worker.py:3801: UserWarning: Large object of size 0.98 MiB detected in task graph: 
      [["('to-parquet-080c68ea005907e78bc9e4b3cbc2a96f', ... dummy.parquet']
    Consider scattering large objects ahead of time
    with client.scatter to reduce scheduler burden and 
    keep data on workers
    
        future = client.submit(func, big_data)    # bad
    
        big_future = client.scatter(big_data)     # good
        future = client.submit(func, big_future)  # good
      warnings.warn(
    

    And the cell ends up throwing an error after killing and restarting workers a few times:

    ---------------------------------------------------------------------------
    KilledWorker                              Traceback (most recent call last)
    <ipython-input-12-559d4aeda91a> in <module>
    ----> 1 data.to_parquet(
          2     "s3://coiled-datasets/dea-opioid/tests/dummy.parquet",
          3     engine='pyarrow',
          4     schema='infer'
          5 )
    
    ~/mambaforge/envs/create-coiled-datasets-m1/lib/python3.9/site-packages/dask/dataframe/core.py in to_parquet(self, path, *args, **kwargs)
       4451         from .io import to_parquet
       4452 
    -> 4453         return to_parquet(self, path, *args, **kwargs)
       4454 
       4455     @derived_from(pd.DataFrame)
    
    ~/mambaforge/envs/create-coiled-datasets-m1/lib/python3.9/site-packages/dask/dataframe/io/parquet/core.py in to_parquet(df, path, engine, compression, write_index, append, overwrite, ignore_divisions, partition_on, storage_options, custom_metadata, write_metadata_file, compute, compute_kwargs, schema, **kwargs)
        719         if compute_kwargs is None:
        720             compute_kwargs = dict()
    --> 721         out = out.compute(**compute_kwargs)
        722     return out
        723 
    
    ~/mambaforge/envs/create-coiled-datasets-m1/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/create-coiled-datasets-m1/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/create-coiled-datasets-m1/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)
       2741                     should_rejoin = False
       2742             try:
    -> 2743                 results = self.gather(packed, asynchronous=asynchronous, direct=direct)
       2744             finally:
       2745                 for f in futures.values():
    
    ~/mambaforge/envs/create-coiled-datasets-m1/lib/python3.9/site-packages/distributed/client.py in gather(self, futures, errors, direct, asynchronous)
       2018             else:
       2019                 local_worker = None
    -> 2020             return self.sync(
       2021                 self._gather,
       2022                 futures,
    
    ~/mambaforge/envs/create-coiled-datasets-m1/lib/python3.9/site-packages/distributed/client.py in sync(self, func, asynchronous, callback_timeout, *args, **kwargs)
        859             return future
        860         else:
    --> 861             return sync(
        862                 self.loop, func, *args, callback_timeout=callback_timeout, **kwargs
        863             )
    
    ~/mambaforge/envs/create-coiled-datasets-m1/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/create-coiled-datasets-m1/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/create-coiled-datasets-m1/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/create-coiled-datasets-m1/lib/python3.9/site-packages/distributed/client.py in _gather(self, futures, errors, direct, local_worker)
       1883                             exc = CancelledError(key)
       1884                         else:
    -> 1885                             raise exception.with_traceback(traceback)
       1886                         raise exc
       1887                     if errors == "skip":
    
    KilledWorker: ("('make-timeseries-436c2767977bc3b5d6a88d86e1bbb3fb', 14872)", <WorkerState 'tls://10.4.1.106:34063', name: coiled-rrpelgr71-36483-worker-638cc5c13e, memory: 0, processing: 1050>)
    

    I'm running:

    • MacOS 11.3.1 (Macbook pro 2020, M1 chip).
    • Python: 3.9.6
    • Dask: 2021.07.1
    • Distributed: 2021.07.1
    • Pyarrow: 5.0.0

    Tagging @fjetter as he's done some debugging work on this, too.

  2. avriiil commented on Aug 17, 2021

    @avriiil
    Contributor

    FWIW this workaround suggested to me by @fjetter does work:

    def submit_jobs():
        from distributed import get_client
        
        with get_client() as client:
            data = dask.datasets.timeseries(
                start="1950",
                end="1951",
            )
            data.to_parquet(
                "s3://coiled-datasets/dea-opioid/tests/dummy-timeseries-170821-2.parquet",
                engine='fastparquet',
            )
            data.compute()
    
    client.submit(submit_jobs).result()
    
  3. fjetter commented on Aug 17, 2021

    @fjetter
    Member

    @rrpelgrim As already discussed, the KilledWorker problem of yours is related to a segmentation fault with pyarrow and is not connected to this issue. The workaround works because you're not using pyarrow. Can you please open a new issue for this?

  4. avriiil commented on Aug 18, 2021

    @avriiil
    Contributor

    @fjetter -- apologies for the confusion, will open a new issue. Would it be best for me to remove my comments above from this thread?

  5. added
    needs attention
    on Oct 25, 2021
  6. jcrist commented on May 27, 2022

    @jcrist
    Member

    All the linked issues have been resolved, closing this in favor of more specific issues.

  7. self-assigned this
    on May 27, 2022
  8. mrocklin commented on May 27, 2022

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

Metadata

Metadata

Assignees

Labels

dataframeioneeds attentionparquet

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions