Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow address instead of redis_address #5412

Merged
merged 9 commits into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 16 additions & 34 deletions python/ray/scripts/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import logging
import os
import subprocess
import sys

import ray.services as services
from ray.autoscaler.commands import (
Expand Down Expand Up @@ -73,6 +72,8 @@ def cli(logging_level, logging_format):
required=False,
type=str,
help="the address to use for connecting to Redis")
@click.option(
"--address", required=False, type=str, help="same as --redis-address")
@click.option(
"--redis-port",
required=False,
Expand Down Expand Up @@ -215,19 +216,26 @@ def cli(logging_level, logging_format):
is_flag=True,
default=False,
help="Specify whether load code from local file or GCS serialization.")
def start(node_ip_address, redis_address, redis_port, num_redis_shards,
redis_max_clients, redis_password, redis_shard_ports,
object_manager_port, node_manager_port, object_store_memory,
redis_max_memory, num_cpus, num_gpus, resources, head, include_webui,
block, plasma_directory, huge_pages, autoscaling_config,
no_redirect_worker_output, no_redirect_output,
def start(node_ip_address, redis_address, address, redis_port,
num_redis_shards, redis_max_clients, redis_password,
redis_shard_ports, object_manager_port, node_manager_port,
object_store_memory, redis_max_memory, num_cpus, num_gpus, resources,
head, include_webui, block, plasma_directory, huge_pages,
autoscaling_config, no_redirect_worker_output, no_redirect_output,
plasma_store_socket_name, raylet_socket_name, temp_dir, include_java,
java_worker_options, load_code_from_local, internal_config):
# Convert hostnames to numerical IP address.
if node_ip_address is not None:
node_ip_address = services.address_to_ip(node_ip_address)
if redis_address is not None:
redis_address = services.address_to_ip(redis_address)
if address:
if redis_address:
raise ValueError(
"You should specify address instead of redis_address.")
ericl marked this conversation as resolved.
Show resolved Hide resolved
if address == "auto":
address = services.find_redis_address_or_die()
redis_address = address

try:
resources = json.loads(resources)
Expand Down Expand Up @@ -751,33 +759,7 @@ def stack():
help="Override the redis address to connect to.")
def timeline(redis_address):
if not redis_address:
import psutil
pids = psutil.pids()
redis_addresses = set()
for pid in pids:
try:
proc = psutil.Process(pid)
for arglist in proc.cmdline():
for arg in arglist.split(" "):
if arg.startswith("--redis-address="):
addr = arg.split("=")[1]
redis_addresses.add(addr)
except psutil.AccessDenied:
pass
except psutil.NoSuchProcess:
pass
if len(redis_addresses) > 1:
logger.info(
"Found multiple active Ray instances: {}. ".format(
redis_addresses) +
"Please specify the one to connect to with --redis-address.")
sys.exit(1)
elif not redis_addresses:
logger.info(
"Could not find any running Ray instance. "
"Please specify the one to connect to with --redis-address.")
sys.exit(1)
redis_address = redis_addresses.pop()
redis_address = services.find_redis_address_or_die()
logger.info("Connecting to Ray instance at {}.".format(redis_address))
ray.init(redis_address=redis_address)
time = datetime.today().strftime("%Y-%m-%d_%H-%M-%S")
Expand Down
32 changes: 32 additions & 0 deletions python/ray/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,38 @@ def include_java_from_redis(redis_client):
return redis_client.get("INCLUDE_JAVA") == b"1"


def find_redis_address_or_die():
try:
import psutil
except ImportError:
raise ImportError(
"Please install `psutil` to automatically detect the Ray cluster.")
pids = psutil.pids()
redis_addresses = set()
for pid in pids:
try:
proc = psutil.Process(pid)
for arglist in proc.cmdline():
for arg in arglist.split(" "):
if arg.startswith("--redis-address="):
addr = arg.split("=")[1]
redis_addresses.add(addr)
except psutil.AccessDenied:
pass
except psutil.NoSuchProcess:
pass
if len(redis_addresses) > 1:
raise ConnectionError(
"Found multiple active Ray instances: {}. ".format(redis_addresses)
+ "Please specify the one to connect to by setting `address`.")
sys.exit(1)
elif not redis_addresses:
raise ConnectionError(
"Could not find any running Ray instance. "
"Please specify the one to connect to by setting `address`.")
return redis_addresses.pop()


def get_address_info_from_redis_helper(redis_address,
node_ip_address,
redis_password=None):
Expand Down
10 changes: 10 additions & 0 deletions python/ray/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ def actor_handle_deserializer(serialized_obj):


def init(redis_address=None,
address=None,
num_cpus=None,
num_gpus=None,
resources=None,
Expand Down Expand Up @@ -1313,6 +1314,7 @@ def init(redis_address=None,
this address is not provided, then this command will start Redis, a
raylet, a plasma store, a plasma manager, and some workers.
It will also kill these processes when Python exits.
address (str): Same as redis_address.
num_cpus (int): Number of cpus the user wishes all raylets to
be configured with.
num_gpus (int): Number of gpus the user wishes all raylets to
Expand Down Expand Up @@ -1376,6 +1378,14 @@ def init(redis_address=None,
arguments is passed in.
"""

if address:
if redis_address:
raise ValueError(
"You should specify address instead of redis_address.")
ericl marked this conversation as resolved.
Show resolved Hide resolved
if address == "auto":
address = services.find_redis_address_or_die()
redis_address = address

if configure_logging:
setup_logger(logging_level, logging_format)

Expand Down
6 changes: 3 additions & 3 deletions rllib/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_parser(parser_creator=None):

# See also the base parser definition in ray/tune/config_parser.py
parser.add_argument(
"--redis-address",
"--ray-address",
default=None,
type=str,
help="Connect to an existing Ray cluster at this address instead "
Expand Down Expand Up @@ -144,10 +144,10 @@ def run(args, parser):
num_gpus=args.ray_num_gpus or 0,
object_store_memory=args.ray_object_store_memory,
redis_max_memory=args.ray_redis_max_memory)
ray.init(redis_address=cluster.redis_address)
ray.init(address=cluster.redis_address)
else:
ray.init(
redis_address=args.redis_address,
address=args.ray_address,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also change all of the examples in tune and rllib?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm purposely not changing them since I don't want users to start using it on old versions of Ray. We can add it to the docs in a couple months.

object_store_memory=args.ray_object_store_memory,
redis_max_memory=args.ray_redis_max_memory,
num_cpus=args.ray_num_cpus,
Expand Down