GithubHelp home page GithubHelp logo

ray-docker-compose's Introduction

Ray Cluster Introduction

A simple example to create a Ray cluster using a custom docker image and a docker compose to configure the (local) cluster.

For more information on Ray:

Build Container

Run the following command in this folder to build the ray container:

docker build -t raytest .

Configure Cluster

Docker compose

A docker compose file was created to configure the cluster for us. You can start it as follows:

docker-compose up

Or optionally run in detatched mode by adding -d.

The dashboard should now be accessible here: http://localhost:8265

Once you are done, tear down the cluster with

docker-compose down

Ports

The following ports are exposed by default:

  • 8265 Ray dashboard
  • 6379 Reddis port to allow external workers to join (optional)
  • 10001 Head node access port to connect external Ray client (optional)

Connect to Cluster

The following is a minimum working example to connect to the cluster head node **

import ray
ray.init(address='ray://<head_node_ip_address>:10001')

** This may require prequisites on your local PC matching those of the cluster.

For example, when running the docker-compose from above, this is running on localhost:10001 by default.

A slightly more advanced example, executing some work on the workers and listing the IPs:

from collections import Counter
import socket
import time

import ray

ray.init(address='ray://localhost:10001')

print('''This cluster consists of
    {} nodes in total
    {} CPU resources in total
'''.format(len(ray.nodes()), ray.cluster_resources()['CPU']))

@ray.remote
def f():
    time.sleep(0.001)
    # Return IP address.
    return socket.gethostbyname(socket.gethostname())

object_ids = [f.remote() for _ in range(10000)]
ip_addresses = ray.get(object_ids)

print('Tasks executed')
for ip_address, num_tasks in Counter(ip_addresses).items():
    print('    {} tasks on {}'.format(num_tasks, ip_address))

or simply run the included script python ray_test.py.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.