From f88a2544bf28a5c75eab3770a10495dc39195578 Mon Sep 17 00:00:00 2001 From: Robert Nishihara Date: Mon, 19 Mar 2018 19:32:46 -0700 Subject: [PATCH] Speed up actor creation task submission by generating IDs with uuid. (#1744) * Speed up actor creation task submission by generating IDs deterministically. * Revert "Speed up actor creation task submission by generating IDs deterministically." This reverts commit 175d9587302664916ce9db4071185485da8da041. * Don't generate actor IDs deterministically yet. * Factor out ID generation method. --- python/ray/actor.py | 14 +++----------- python/ray/utils.py | 8 +++++++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/python/ray/actor.py b/python/ray/actor.py index 1ef5f095a..04d78e926 100644 --- a/python/ray/actor.py +++ b/python/ray/actor.py @@ -12,18 +12,10 @@ import ray.cloudpickle as pickle import ray.local_scheduler import ray.signature as signature import ray.worker -from ray.utils import (FunctionProperties, random_string, is_cython, +from ray.utils import (FunctionProperties, _random_string, is_cython, push_error_to_driver) -def random_actor_id(): - return ray.local_scheduler.ObjectID(random_string()) - - -def random_actor_class_id(): - return random_string() - - def compute_actor_handle_id(actor_handle_id, num_forks): """Deterministically comopute an actor handle ID. @@ -750,7 +742,7 @@ def actor_handle_from_class(Class, class_id, actor_creation_resources, raise Exception("Actors cannot be created before ray.init() " "has been called.") - actor_id = random_actor_id() + actor_id = ray.local_scheduler.ObjectID(_random_string()) # The ID for this instance of ActorHandle. These should be unique # across instances with the same _ray_actor_id. actor_handle_id = ray.local_scheduler.ObjectID( @@ -930,7 +922,7 @@ def make_actor(cls, resources, checkpoint_interval, actor_method_cpus): Class.__module__ = cls.__module__ Class.__name__ = cls.__name__ - class_id = random_actor_class_id() + class_id = _random_string() return actor_handle_from_class(Class, class_id, resources, checkpoint_interval, actor_method_cpus) diff --git a/python/ray/utils.py b/python/ray/utils.py index 4b9a85a13..9a072ff60 100644 --- a/python/ray/utils.py +++ b/python/ray/utils.py @@ -4,9 +4,11 @@ from __future__ import print_function import binascii import collections +import hashlib import numpy as np import os import sys +import uuid import ray.local_scheduler @@ -15,7 +17,11 @@ DRIVER_ID_LENGTH = 20 def _random_string(): - return np.random.bytes(20) + id_hash = hashlib.sha1() + id_hash.update(uuid.uuid4().bytes) + id_bytes = id_hash.digest() + assert len(id_bytes) == 20 + return id_bytes def format_error_message(exception_message, task_exception=False):