Skip to content

dask.Bag slow and very large memory consumption with join #3252

Closed

Description

@gabrielelanaro

In a certain application I am passing a (moderately) large argument to Bag.join. But I am encountering a few issues:

  • The graph does not appear in the diagnostics page (presumably the graph is being communicated)
  • The client consumes GB of memory

I suspect this has to do with the fact that tasks are serialized individually and this large argument gets serialized multiple times.

This is the code to reproduce the issue:

import dask, distributed
from dask.distributed import Client
from dask.sizeof import sizeof
import dask.bag as db
import time

dask.__version__
# '0.17.1'
distributed.__version__
# '1.21.0'
c = Client()
data = list(range(1000000))
sizeof(data) # 37 Mb

start = time.time()
bag = db.from_sequence(range(100000), npartitions=100).join(data, lambda x: x)
print("Graph creation time", time.time() - start)
# Graph creation time 1.0362498760223389

start = time.time()
bag.count().compute()
print("Graph computation time", time.time() - start)

# This consumes GB of memory

Activity

  1. mrocklin commented on Mar 8, 2018

    @mrocklin
    Member

    First, have you considered using dask.dataframe? The join operations there will be much faster. It may be that your data doesn't fit nicely into dask.dataframe, but I thought I'd check.

  2. mrocklin commented on Mar 8, 2018

    @mrocklin
    Member

    See #3254 for a partial fix and the docstring especially for suggestions.

    I recommend the following:

     join(dask.delayed(tuple(data)), ...
    
  3. gabrielelanaro commented on Mar 8, 2018

    @gabrielelanaro
    ContributorAuthor

    Thank you so much @mrocklin . Yes I did try DataFrame and it is much better.

    I've been introducing dask to my colleagues (the "industry case" you were mentioning in one of your talk), and I'm finding that almost all of the issues they're having are related to large object or large partials/closures (say, when you're trying to parallelize some pure-python workflow, written by non-scientists and you need to pass these objects around). So I thought I'd report these kind of issues anyway to help the project get adopted faster in the industry.

    I was actually thinking that this kind of optimizations could be implemented as an optimizer pass. But let me know if you think this is a good idea.

    given the dask graph:

    1. recursively (up to a certain depth maybe) visit the "task tuples"
    2. for each object measure its size
    3. also keep a counter of how many time an object was encountered (keep track using the id function)
    4. store the object in another node and replace the original argument with a key

    Do you think this is a feasible approach? I'm afraid the recursive calculation of sizes may be really slow. If you think this make sense I can stub a PR.

  4. mrocklin commented on Mar 8, 2018

    @mrocklin
    Member

    Yes, I think that that would be a feasible approach. An optional optimization would be the right place to add that.

    As you suggest, there might be costs associated with determining the size of objects. This cost might be reduced somewhat by only considering those objects that are included in the graph several times, and are not base types (ints, floats, strings, ...) (so swap steps 2 and 3?)

    A PR exploring this topic would be welcome. I agree that this is a common issue that trips up new users.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions