示例#1
0
def chunk_put(req: ray_client_pb2.DataRequest):
    """
    Chunks a put request. Doing this lazily is important for large objects,
    since taking slices of bytes objects does a copy. This means if we
    immediately materialized every chunk of a large object and inserted them
    into the result_queue, we would effectively double the memory needed
    on the client to handle the put.
    """
    total_size = len(req.put.data)
    assert total_size > 0, "Cannot chunk object with missing data"
    if total_size >= OBJECT_TRANSFER_WARNING_SIZE and log_once(
            "client_object_put_size_warning"):
        size_gb = total_size / 2**30
        warnings.warn(
            "Ray Client is attempting to send a "
            f"{size_gb:.2f} GiB object over the network, which may "
            "be slow. Consider serializing the object and using a remote "
            "URI to transfer via S3 or Google Cloud Storage instead. "
            "Documentation for doing this can be found here: "
            "https://docs.ray.io/en/latest/handling-dependencies.html#remote-uris",
            UserWarning,
        )
    total_chunks = math.ceil(total_size / OBJECT_TRANSFER_CHUNK_SIZE)
    for chunk_id in range(0, total_chunks):
        start = chunk_id * OBJECT_TRANSFER_CHUNK_SIZE
        end = min(total_size, (chunk_id + 1) * OBJECT_TRANSFER_CHUNK_SIZE)
        chunk = ray_client_pb2.PutRequest(
            client_ref_id=req.put.client_ref_id,
            data=req.put.data[start:end],
            chunk_id=chunk_id,
            total_chunks=total_chunks,
            total_size=total_size,
        )
        yield ray_client_pb2.DataRequest(req_id=req.req_id, put=chunk)
示例#2
0
def test_prepare_runtime_init_req_fails():
    """
    Check that a connection that is initiated with a non-Init request
    raises an error.
    """
    put_req = ray_client_pb2.DataRequest(put=ray_client_pb2.PutRequest())
    with pytest.raises(AssertionError):
        proxier.prepare_runtime_init_req(put_req)
示例#3
0
文件: worker.py 项目: alipay/ray
 def _put_pickled(self, data, client_ref_id: bytes):
     req = ray_client_pb2.PutRequest(data=data)
     if client_ref_id is not None:
         req.client_ref_id = client_ref_id
     resp = self.data_client.PutObject(req)
     if not resp.valid:
         try:
             raise cloudpickle.loads(resp.error)
         except (pickle.UnpicklingError, TypeError):
             logger.exception("Failed to deserialize {}".format(resp.error))
             raise
     return ClientObjectRef(resp.id)
示例#4
0
 def _put(self, val):
     if isinstance(val, ClientObjectRef):
         raise TypeError(
             "Calling 'put' on an ObjectRef is not allowed "
             "(similarly, returning an ObjectRef from a remote "
             "function is not allowed). If you really want to "
             "do this, you can wrap the ObjectRef in a list and "
             "call 'put' on it (or return it).")
     data = dumps_from_client(val, self._client_id)
     req = ray_client_pb2.PutRequest(data=data)
     resp = self.data_client.PutObject(req)
     return ClientObjectRef(resp.id)
示例#5
0
 def _put(self, val, *, client_ref_id: bytes = None):
     if isinstance(val, ClientObjectRef):
         raise TypeError(
             "Calling 'put' on an ObjectRef is not allowed "
             "(similarly, returning an ObjectRef from a remote "
             "function is not allowed). If you really want to "
             "do this, you can wrap the ObjectRef in a list and "
             "call 'put' on it (or return it).")
     data = dumps_from_client(val, self._client_id)
     req = ray_client_pb2.PutRequest(data=data)
     if client_ref_id is not None:
         req.client_ref_id = client_ref_id
     resp = self.data_client.PutObject(req)
     if not resp.valid:
         try:
             raise cloudpickle.loads(resp.error)
         except pickle.UnpicklingError:
             logger.exception("Failed to deserialize {}".format(resp.error))
             raise
     return ClientObjectRef(resp.id)
示例#6
0
 def _put(self, val):
     data = cloudpickle.dumps(val)
     req = ray_client_pb2.PutRequest(data=data)
     resp = self.server.PutObject(req)
     return ClientObjectRef(resp.id)
示例#7
0
文件: worker.py 项目: tseiger1/ray
 def _put(self, val):
     data = cloudpickle.dumps(val)
     req = ray_client_pb2.PutRequest(data=data)
     resp = self.server.PutObject(req, metadata=self.metadata)
     return ClientObjectRef.from_remote_ref(resp.ref)
示例#8
0
 def _put(self, val):
     data = dumps_from_client(val, self._client_id)
     req = ray_client_pb2.PutRequest(data=data)
     resp = self.data_client.PutObject(req)
     return ClientObjectRef(resp.id)