unify starting local cluster with attaching to existing cluster (#327)

This commit is contained in:
Robert Nishihara
2016-07-31 19:26:35 -07:00
committed by Philipp Moritz
parent 0e5b858324
commit 2040372084
17 changed files with 104 additions and 90 deletions
+14 -6
View File
@@ -169,14 +169,22 @@ class RayCluster(object):
start_workers_commands.append(start_workers_command)
self._run_command_over_ssh_on_all_nodes_in_parallel(start_workers_commands)
print "cluster started; you can start the shell on the head node with:"
setup_env_path = os.path.join(self.installation_directory, "ray/setup-env.sh")
shell_script_path = os.path.join(self.installation_directory, "ray/scripts/shell.py")
print """
cd "{}";
source "{}";
python "{}" --scheduler-address={}:10001 --objstore-address={}:20001 --worker-address={}:30001 --attach
""".format(remote_user_source_directory, setup_env_path, shell_script_path, self.node_private_ip_addresses[0], self.node_private_ip_addresses[0], self.node_private_ip_addresses[0])
The cluster has been started. You can attach to the cluster by sshing to the head node with the following command.
ssh -i {} {}@{}
Then run the following commands.
cd {}
source {}
Then within a Python interpreter, run the following commands.
import ray
ray.init(scheduler_address="{}:10001", objstore_address="{}:20001", driver_address="{}:30001")
""".format(self.key_file, self.username, self.node_ip_addresses[0], remote_user_source_directory, setup_env_path, self.node_private_ip_addresses[0], self.node_private_ip_addresses[0], self.node_private_ip_addresses[0])
def stop_ray(self):
"""Kill all of the processes in the Ray cluster.
-35
View File
@@ -1,35 +0,0 @@
#!/usr/bin/env python
import os
import sys
import numpy as np
import ray
def main(argv):
DEFAULT_NUM_WORKERS = 1
DEFAULT_WORKER_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "default_worker.py")
import argparse # No need for this to be global
parser = argparse.ArgumentParser(description="Parse shell options")
parser.add_argument("--scheduler-address", default="127.0.0.1:10001", type=str, help="the scheduler's address")
parser.add_argument("--objstore-address", default="127.0.0.1:20001", type=str, help="the objstore's address")
parser.add_argument("--worker-address", default="127.0.0.1:30001", type=str, help="the worker's address")
parser.add_argument("--attach", action="store_true", help="If true, attach the shell to an already running cluster. If false, start a new cluster.")
parser.add_argument("--worker-path", type=str, help="Path to the worker script")
parser.add_argument("--num-workers", type=int, help="Number of workers to start")
args, unknown_args = parser.parse_known_args(argv)
if args.attach:
assert args.worker_path is None, "when attaching, no new worker can be started"
assert args.num_workers is None, "when attaching, no new worker can be started"
ray.worker.connect(args.scheduler_address, args.objstore_address, args.worker_address, is_driver=True, mode=ray.SHELL_MODE)
else:
ray.services.start_ray_local(num_workers=args.num_workers if not args.num_workers is None else DEFAULT_NUM_WORKERS,
worker_path=args.worker_path if not args.worker_path is None else DEFAULT_WORKER_PATH,
driver_mode=ray.SHELL_MODE)
return unknown_args
if __name__ == "__main__":
import IPython
IPython.terminal.ipapp.launch_new_instance(argv=main(sys.argv[1:]), user_ns=globals())