コード例 #1
0
    def _process_key(self, key):
        """Process the given export key from redis."""
        # Handle the driver case first.
        if self.mode != ray.WORKER_MODE:
            if key.startswith(b"FunctionsToRun"):
                with profiling.profile("fetch_and_run_function",
                                       worker=self.worker):
                    self.fetch_and_execute_function_to_run(key)
            # Return because FunctionsToRun are the only things that
            # the driver should import.
            return

        if key.startswith(b"RemoteFunction"):
            with profiling.profile("register_remote_function",
                                   worker=self.worker):
                self.fetch_and_register_remote_function(key)
        elif key.startswith(b"FunctionsToRun"):
            with profiling.profile("fetch_and_run_function",
                                   worker=self.worker):
                self.fetch_and_execute_function_to_run(key)
        elif key.startswith(b"ActorClass"):
            # Keep track of the fact that this actor class has been
            # exported so that we know it is safe to turn this worker
            # into an actor of that class.
            self.worker.imported_actor_classes.add(key)
        # TODO(rkn): We may need to bring back the case of
        # fetching actor classes here.
        else:
            raise Exception("This code should be unreachable.")
コード例 #2
0
ファイル: import_thread.py プロジェクト: robertnishihara/ray
    def _process_key(self, key):
        """Process the given export key from redis."""
        # Handle the driver case first.
        if self.mode != ray.WORKER_MODE:
            if key.startswith(b"FunctionsToRun"):
                with profiling.profile("fetch_and_run_function"):
                    self.fetch_and_execute_function_to_run(key)
            # Return because FunctionsToRun are the only things that
            # the driver should import.
            return

        if key.startswith(b"RemoteFunction"):
            with profiling.profile("register_remote_function"):
                (self.worker.function_actor_manager.
                 fetch_and_register_remote_function(key))
        elif key.startswith(b"FunctionsToRun"):
            with profiling.profile("fetch_and_run_function"):
                self.fetch_and_execute_function_to_run(key)
        elif key.startswith(b"ActorClass"):
            # Keep track of the fact that this actor class has been
            # exported so that we know it is safe to turn this worker
            # into an actor of that class.
            self.worker.function_actor_manager.imported_actor_classes.add(key)
        # TODO(rkn): We may need to bring back the case of
        # fetching actor classes here.
        else:
            raise Exception("This code should be unreachable.")
コード例 #3
0
ファイル: import_thread.py プロジェクト: xiaming9880/ray
    def _process_key(self, key):
        """Process the given export key from redis."""
        # Handle the driver case first.
        if self.mode != ray.WORKER_MODE:
            if key.startswith(b"FunctionsToRun"):
                with profiling.profile("fetch_and_run_function"):
                    self.fetch_and_execute_function_to_run(key)

            # If the same remote function or actor definition appears to be
            # exported many times, then print a warning. We only issue this
            # warning from the driver so that it is only triggered once instead
            # of many times. TODO(rkn): We may want to push this to the driver
            # through Redis so that it can be displayed in the dashboard more
            # easily.
            elif (key.startswith(b"RemoteFunction")
                  or key.startswith(b"ActorClass")):
                collision_identifier, name, import_type = (
                    self._get_import_info_for_collision_detection(key))
                self.imported_collision_identifiers[collision_identifier] += 1
                if (self.imported_collision_identifiers[collision_identifier]
                        == ray_constants.DUPLICATE_REMOTE_FUNCTION_THRESHOLD):
                    logger.warning(
                        "The %s '%s' has been exported %s times. It's "
                        "possible that this warning is accidental, but this "
                        "may indicate that the same remote function is being "
                        "defined repeatedly from within many tasks and "
                        "exported to all of the workers. This can be a "
                        "performance issue and can be resolved by defining "
                        "the remote function on the driver instead. See "
                        "https://github.com/ray-project/ray/issues/6240 for "
                        "more discussion.", import_type, name,
                        ray_constants.DUPLICATE_REMOTE_FUNCTION_THRESHOLD)

            # Return because FunctionsToRun are the only things that
            # the driver should import.
            return

        if key.startswith(b"RemoteFunction"):
            with profiling.profile("register_remote_function"):
                (self.worker.function_actor_manager.
                 fetch_and_register_remote_function(key))
        elif key.startswith(b"FunctionsToRun"):
            with profiling.profile("fetch_and_run_function"):
                self.fetch_and_execute_function_to_run(key)
        elif key.startswith(b"ActorClass"):
            # Keep track of the fact that this actor class has been
            # exported so that we know it is safe to turn this worker
            # into an actor of that class.
            self.worker.function_actor_manager.imported_actor_classes.add(key)
        # TODO(rkn): We may need to bring back the case of
        # fetching actor classes here.
        else:
            raise Exception("This code should be unreachable.")
コード例 #4
0
    def get_execution_info(self, job_id, function_descriptor):
        """Get the FunctionExecutionInfo of a remote function.

        Args:
            job_id: ID of the job that the function belongs to.
            function_descriptor: The FunctionDescriptor of the function to get.

        Returns:
            A FunctionExecutionInfo object.
        """
        if self._worker.load_code_from_local:
            # Load function from local code.
            # Currently, we don't support isolating code by jobs,
            # thus always set job ID to NIL here.
            job_id = ray.JobID.nil()
            if not function_descriptor.is_actor_method():
                self._load_function_from_local(job_id, function_descriptor)
        else:
            # Load function from GCS.
            # Wait until the function to be executed has actually been
            # registered on this worker. We will push warnings to the user if
            # we spend too long in this loop.
            # The driver function may not be found in sys.path. Try to load
            # the function from GCS.
            with profiling.profile("wait_for_function"):
                self._wait_for_function(function_descriptor, job_id)
        try:
            function_id = function_descriptor.function_id
            info = self._function_execution_info[job_id][function_id]
        except KeyError as e:
            message = ("Error occurs in get_execution_info: "
                       "job_id: %s, function_descriptor: %s. Message: %s" %
                       (job_id, function_descriptor, e))
            raise KeyError(message)
        return info
コード例 #5
0
ファイル: function_manager.py プロジェクト: yukoba/ray
    def get_execution_info(self, driver_id, function_descriptor):
        """Get the FunctionExecutionInfo of a remote function.

        Args:
            driver_id: ID of the driver that the function belongs to.
            function_descriptor: The FunctionDescriptor of the function to get.

        Returns:
            A FunctionExecutionInfo object.
        """
        function_id = function_descriptor.function_id

        # Wait until the function to be executed has actually been
        # registered on this worker. We will push warnings to the user if
        # we spend too long in this loop.
        # The driver function may not be found in sys.path. Try to load
        # the function from GCS.
        with profiling.profile("wait_for_function", worker=self._worker):
            self._wait_for_function(function_descriptor, driver_id)
        try:
            info = self._function_execution_info[driver_id][function_id]
        except KeyError as e:
            message = ("Error occurs in get_execution_info: "
                       "driver_id: %s, function_descriptor: %s. Message: %s" %
                       (driver_id, function_descriptor, e))
            raise KeyError(message)
        return info
コード例 #6
0
ファイル: internal_api.py プロジェクト: zdpau/ray-1
def free(object_ids, local_only=False, worker=None):
    """Free a list of IDs from object stores.

    This function is a low-level API which should be used in restricted
    scenarios.

    If local_only is false, the request will be send to all object stores.

    This method will not return any value to indicate whether the deletion is
    successful or not. This function is an instruction to object store. If
    the some of the objects are in use, object stores will delete them later
    when the ref count is down to 0.

    Args:
        object_ids (List[ObjectID]): List of object IDs to delete.
        local_only (bool): Whether only deleting the list of objects in local
            object store or all object stores.
    """
    if worker is None:
        worker = ray.worker.get_global_worker()

    if isinstance(object_ids, ray.ObjectID):
        object_ids = [object_ids]

    if not isinstance(object_ids, list):
        raise TypeError("free() expects a list of ObjectID, got {}".format(
            type(object_ids)))

    worker.check_connected()
    with profiling.profile("ray.free", worker=worker):
        if len(object_ids) == 0:
            return

        worker.raylet_client.free_objects(object_ids, local_only)
コード例 #7
0
    def get_execution_info(self, driver_id, function_descriptor):
        """Get the FunctionExecutionInfo of a remote function.

        Args:
            driver_id: ID of the driver that the function belongs to.
            function_descriptor: The FunctionDescriptor of the function to get.

        Returns:
            A FunctionExecutionInfo object.
        """
        if self._worker.load_code_from_local:
            # Load function from local code.
            # Currently, we don't support isolating code by drivers,
            # thus always set driver ID to NIL here.
            driver_id = ray.DriverID.nil()
            if not function_descriptor.is_actor_method():
                self._load_function_from_local(driver_id, function_descriptor)
        else:
            # Load function from GCS.
            # Wait until the function to be executed has actually been
            # registered on this worker. We will push warnings to the user if
            # we spend too long in this loop.
            # The driver function may not be found in sys.path. Try to load
            # the function from GCS.
            with profiling.profile("wait_for_function"):
                self._wait_for_function(function_descriptor, driver_id)
        try:
            function_id = function_descriptor.function_id
            info = self._function_execution_info[driver_id][function_id]
        except KeyError as e:
            message = ("Error occurs in get_execution_info: "
                       "driver_id: %s, function_descriptor: %s. Message: %s" %
                       (driver_id, function_descriptor, e))
            raise KeyError(message)
        return info
コード例 #8
0
    def _actor_method_call(self,
                           method_name,
                           args=None,
                           kwargs=None,
                           num_return_vals=None):
        """Method execution stub for an actor handle.

        This is the function that executes when
        `actor.method_name.remote(*args, **kwargs)` is called. Instead of
        executing locally, the method is packaged as a task and scheduled
        to the remote actor instance.

        Args:
            method_name: The name of the actor method to execute.
            args: A list of arguments for the actor method.
            kwargs: A dictionary of keyword arguments for the actor method.
            num_return_vals (int): The number of return values for the method.

        Returns:
            object_ids: A list of object IDs returned by the remote actor
                method.
        """
        worker = ray.worker.get_global_worker()

        worker.check_connected()

        function_signature = self._ray_method_signatures[method_name]
        if args is None:
            args = []
        if kwargs is None:
            kwargs = {}
        args = signature.extend_args(function_signature, args, kwargs)

        function_descriptor = FunctionDescriptor(self._ray_module_name,
                                                 method_name,
                                                 self._ray_class_name)

        with profiling.profile("submit_task"):
            if worker.mode == ray.LOCAL_MODE:
                function = getattr(worker.actors[self._actor_id], method_name)
                object_ids = worker.local_mode_manager.execute(
                    function, function_descriptor, args, num_return_vals)
            else:
                object_ids = worker.core_worker.submit_actor_task(
                    self._ray_core_handle,
                    function_descriptor.get_function_descriptor_list(), args,
                    num_return_vals, {"CPU": self._ray_actor_method_cpus})

        if len(object_ids) == 1:
            object_ids = object_ids[0]
        elif len(object_ids) == 0:
            object_ids = None

        return object_ids
コード例 #9
0
ファイル: internal_api.py プロジェクト: ray1201/ray-1
def free(object_ids, local_only=False, delete_creating_tasks=False):
    """Free a list of IDs from object stores.

    This function is a low-level API which should be used in restricted
    scenarios.

    If local_only is false, the request will be send to all object stores.

    This method will not return any value to indicate whether the deletion is
    successful or not. This function is an instruction to object store. If
    the some of the objects are in use, object stores will delete them later
    when the ref count is down to 0.

    Examples:
        >>> x_id = f.remote()
        >>> ray.get(x_id)  # wait for x to be created first
        >>> free([x_id])  # unpin & delete x globally

    Args:
        object_ids (List[ObjectID]): List of object IDs to delete.
        local_only (bool): Whether only deleting the list of objects in local
            object store or all object stores.
        delete_creating_tasks (bool): Whether also delete the object creating
            tasks.
    """
    worker = ray.worker.get_global_worker()

    if isinstance(object_ids, ray.ObjectID):
        object_ids = [object_ids]

    if not isinstance(object_ids, list):
        raise TypeError("free() expects a list of ObjectID, got {}".format(
            type(object_ids)))

    # Make sure that the values are object IDs.
    for object_id in object_ids:
        if not isinstance(object_id, ray.ObjectID):
            raise TypeError("Attempting to call `free` on the value {}, "
                            "which is not an ray.ObjectID.".format(object_id))
        unpin_object_data(object_id)

    if ray.worker._mode() == ray.worker.LOCAL_MODE:
        worker.local_mode_manager.free(object_ids)
        return

    worker.check_connected()
    with profiling.profile("ray.free"):
        if len(object_ids) == 0:
            return

        worker.raylet_client.free_objects(object_ids, local_only,
                                          delete_creating_tasks)
コード例 #10
0
ファイル: function_manager.py プロジェクト: valldabo2/ray
    def get_execution_info(self, driver_id, function_id):
        """Get the FunctionExecutionInfo of a remote function.

        Args:
            driver_id: ID of the driver that the function belongs to.
            function_id: ID of the function to get.

        Returns:
            A FunctionExecutionInfo object.
        """
        # Wait until the function to be executed has actually been registered
        # on this worker. We will push warnings to the user if we spend too
        # long in this loop.
        with profiling.profile("wait_for_function", worker=self._worker):
            self._wait_for_function(function_id, driver_id)
        return self._function_execution_info[driver_id][function_id.id()]
コード例 #11
0
ファイル: internal_api.py プロジェクト: fcardoso75/ray
def free(object_refs, local_only=False):
    """Free a list of IDs from the in-process and plasma object stores.

    This function is a low-level API which should be used in restricted
    scenarios.

    If local_only is false, the request will be send to all object stores.

    This method will not return any value to indicate whether the deletion is
    successful or not. This function is an instruction to the object store. If
    some of the objects are in use, the object stores will delete them later
    when the ref count is down to 0.

    Examples:
        >>> x_id = f.remote()
        >>> ray.get(x_id)  # wait for x to be created first
        >>> free([x_id])  # unpin & delete x globally

    Args:
        object_refs (List[ObjectRef]): List of object refs to delete.
        local_only (bool): Whether only deleting the list of objects in local
            object store or all object stores.
    """
    worker = ray.worker.global_worker

    if isinstance(object_refs, ray.ObjectRef):
        object_refs = [object_refs]

    if not isinstance(object_refs, list):
        raise TypeError("free() expects a list of ObjectRef, got {}".format(
            type(object_refs)))

    # Make sure that the values are object refs.
    for object_ref in object_refs:
        if not isinstance(object_ref, ray.ObjectRef):
            raise TypeError(
                "Attempting to call `free` on the value {}, "
                "which is not an ray.ObjectRef.".format(object_ref))

    worker.check_connected()
    with profiling.profile("ray.free"):
        if len(object_refs) == 0:
            return

        worker.core_worker.free_objects(object_refs, local_only)
コード例 #12
0
    def get_execution_info(self, driver_id, function_descriptor):
        """Get the FunctionExecutionInfo of a remote function.

        Args:
            driver_id: ID of the driver that the function belongs to.
            function_descriptor: The FunctionDescriptor of the function to get.

        Returns:
            A FunctionExecutionInfo object.
        """
        function_id = function_descriptor.function_id.id()

        # Wait until the function to be executed has actually been
        # registered on this worker. We will push warnings to the user if
        # we spend too long in this loop.
        # The driver function may not be found in sys.path. Try to load
        # the function from GCS.
        with profiling.profile("wait_for_function", worker=self._worker):
            self._wait_for_function(function_descriptor, driver_id)
        return self._function_execution_info[driver_id][function_id]
コード例 #13
0
ファイル: internal_api.py プロジェクト: robertnishihara/ray
def free(object_ids, local_only=False):
    """Free a list of IDs from object stores.

    This function is a low-level API which should be used in restricted
    scenarios.

    If local_only is false, the request will be send to all object stores.

    This method will not return any value to indicate whether the deletion is
    successful or not. This function is an instruction to object store. If
    the some of the objects are in use, object stores will delete them later
    when the ref count is down to 0.

    Args:
        object_ids (List[ObjectID]): List of object IDs to delete.
        local_only (bool): Whether only deleting the list of objects in local
            object store or all object stores.
    """
    worker = ray.worker.get_global_worker()

    if isinstance(object_ids, ray.ObjectID):
        object_ids = [object_ids]

    if not isinstance(object_ids, list):
        raise TypeError("free() expects a list of ObjectID, got {}".format(
            type(object_ids)))

    # Make sure that the values are object IDs.
    for object_id in object_ids:
        if not isinstance(object_id, ray.ObjectID):
            raise TypeError("Attempting to call `free` on the value {}, "
                            "which is not an ray.ObjectID.".format(object_id))

    worker.check_connected()
    with profiling.profile("ray.free"):
        if len(object_ids) == 0:
            return

        worker.raylet_client.free_objects(object_ids, local_only)