Skip to content

Cleanup worker.py #2016

Closed
Closed

Description

@suquark

Describe the problem

Currently, ray/worker.py seems too heavy. It contains ~3000 lines of code (maybe 1/3 of core python code of ray).

And its a bit messy (contains nearly all kinds of structure-breaking reference🙃) :

global_worker = Worker()

class Worker:
    def func_a(self):
        foo(worker=self)
        
    def func_b(self):
        foo()
        
    def func_c(self):
        put()

    def func_d(self):
        bar(worker=self)

    def func_d(self):
        bar(worker=global_worker)

def foo(worker=global_worker):
    pass

def bar(worker):
    pass

def put():
    do_something(global_worker)

What's more, worker.py contains all these things:

  • logging utils
  • serialization utils
  • core worker logics
  • ray APIs
  • ray exceptions
  • constants

Since a possible correct dependency may look like:

image

, it could be better to divide worker.py into several independent modules. We could keep ray's APIs in worker.py so it may not affect other parts of ray.

I want to know if a PR for refactoring worker.py is welcomed? (I understand that such a PR is heavy and may be unnecessary now.)

Activity

  1. robertnishihara commented on May 9, 2018

    @robertnishihara
    Collaborator

    @suquark thanks for bringing this up, you're right that worker.py is messy, and a lot of reorganization needs to happen :)

    This is roughly the same issue as #614.

    How would you suggest structuring the code? It'd be nice to define the Worker class better, and it should be possible to do things like create multiple Workers in the same process. Then the Ray API would probably be very minimal and just directly call methods on a global_worker.

    Another thing is that there are some related concepts, there are Workers that are used for workers, actors, and drivers, and maybe these should be related by subclassing some sort of RayClient class.

    It may make sense to get rid of actor.py, but I'm not completely sure.

  2. robertnishihara commented on May 10, 2018

    @robertnishihara
    Collaborator

    I'm currently doing some cleanups in worker.py so maybe hold off for the moment.

  3. added
    P3
    on Mar 5, 2020
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

    P3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions