motcke
motcke

Reputation: 437

Connecting to Multiple ray.io Remote Addresses Simultaneously

I have a service that runs remote ray tasks. Currently, all tasks run on the same ray cluster, but I want to be able to run some other tasks on another ray cluster.

The way it's initialized today is using ray.init(address=ray_cluster_1) while initializing the service, and then in the code, I call decorated functions using foo.remote().

Is it possible to initialize two addresses and decide which one to call?

Something like:

ray.init(addresses=[ray_cluster_1, ray_cluster_2])

@ray.remote
def foo()
    pass

foo.remote(address=ray_cluster_1)
foo.remote(address=ray_cluster_2)

if not, the only option that I see is to have two different services, one per ray. Suggestions?

Upvotes: 1

Views: 896

Answers (1)

Alex
Alex

Reputation: 1448

Ray has experimental support with this by treating the output of ray.init as a context manager.

Note that you must be using Ray Client to connect to your ray cluster https://docs.ray.io/en/latest/cluster/ray-client.html#connect-to-multiple-ray-clusters-experimental

import ray
# Create a default client.
ray.init("ray://<head_node_host_cluster>:10001")

# Connect to other clusters.
cli1 = ray.init("ray://<head_node_host_cluster_1>:10001", allow_multiple=True)
cli2 = ray.init("ray://<head_node_host_cluster_2>:10001", allow_multiple=True)

# Data is put into the default cluster.
obj = ray.put("obj")

with cli1:
    obj1 = ray.put("obj1")

with cli2:
    obj2 = ray.put("obj2")

Upvotes: 2

Related Questions