mirror of
https://github.com/wassname/ray.git
synced 2026-07-08 20:48:35 +08:00
[Streaming] Streaming data transfer supports cross language. (#7961)
* add init parameters for java * fix bug * cython * fix compile * fix test_direct_tranfer * comment * ChannelCreationParameter * fix comment * builder * lint and fix tests * fix single process test * fix checkstyle and lint * checkstyle * lint python Co-authored-by: wanxing <wanxing@B-458DMD6M-1753.local>
This commit is contained in:
@@ -135,8 +135,7 @@ void WriterQueue::Send() {
|
||||
item.IsRaw());
|
||||
std::unique_ptr<LocalMemoryBuffer> buffer = msg.ToBytes();
|
||||
STREAMING_CHECK(transport_ != nullptr);
|
||||
transport_->Send(std::move(buffer),
|
||||
DownstreamQueueMessageHandler::peer_async_function_);
|
||||
transport_->Send(std::move(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +187,7 @@ void ReaderQueue::Notify(uint64_t seq_id) {
|
||||
NotificationMessage msg(actor_id_, peer_actor_id_, queue_id_, seq_id);
|
||||
std::unique_ptr<LocalMemoryBuffer> buffer = msg.ToBytes();
|
||||
|
||||
transport_->Send(std::move(buffer), UpstreamQueueMessageHandler::peer_async_function_);
|
||||
transport_->Send(std::move(buffer));
|
||||
}
|
||||
|
||||
void ReaderQueue::CreateNotifyTask(uint64_t seq_id, std::vector<TaskArg> &task_args) {}
|
||||
|
||||
@@ -17,9 +17,7 @@ class ReaderClient {
|
||||
/// \param[in] async_func DataReader's raycall function descriptor to be called by
|
||||
/// DataWriter, asynchronous semantics \param[in] sync_func DataReader's raycall
|
||||
/// function descriptor to be called by DataWriter, synchronous semantics
|
||||
ReaderClient(RayFunction &async_func, RayFunction &sync_func) {
|
||||
DownstreamQueueMessageHandler::peer_async_function_ = async_func;
|
||||
DownstreamQueueMessageHandler::peer_sync_function_ = sync_func;
|
||||
ReaderClient() {
|
||||
downstream_handler_ = ray::streaming::DownstreamQueueMessageHandler::CreateService(
|
||||
CoreWorkerProcess::GetCoreWorker().GetWorkerContext().GetCurrentActorID());
|
||||
}
|
||||
@@ -38,9 +36,7 @@ class ReaderClient {
|
||||
/// Interface of streaming queue for DataWriter. Similar to ReaderClient.
|
||||
class WriterClient {
|
||||
public:
|
||||
WriterClient(RayFunction &async_func, RayFunction &sync_func) {
|
||||
UpstreamQueueMessageHandler::peer_async_function_ = async_func;
|
||||
UpstreamQueueMessageHandler::peer_sync_function_ = sync_func;
|
||||
WriterClient() {
|
||||
upstream_handler_ = ray::streaming::UpstreamQueueMessageHandler::CreateService(
|
||||
CoreWorkerProcess::GetCoreWorker().GetWorkerContext().GetCurrentActorID());
|
||||
}
|
||||
|
||||
@@ -12,11 +12,6 @@ std::shared_ptr<UpstreamQueueMessageHandler>
|
||||
std::shared_ptr<DownstreamQueueMessageHandler>
|
||||
DownstreamQueueMessageHandler::downstream_handler_ = nullptr;
|
||||
|
||||
RayFunction UpstreamQueueMessageHandler::peer_sync_function_;
|
||||
RayFunction UpstreamQueueMessageHandler::peer_async_function_;
|
||||
RayFunction DownstreamQueueMessageHandler::peer_sync_function_;
|
||||
RayFunction DownstreamQueueMessageHandler::peer_async_function_;
|
||||
|
||||
std::shared_ptr<Message> QueueMessageHandler::ParseMessage(
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer) {
|
||||
uint8_t *bytes = buffer->Data();
|
||||
@@ -83,10 +78,11 @@ std::shared_ptr<Transport> QueueMessageHandler::GetOutTransport(
|
||||
}
|
||||
|
||||
void QueueMessageHandler::SetPeerActorID(const ObjectID &queue_id,
|
||||
const ActorID &actor_id) {
|
||||
const ActorID &actor_id, RayFunction &async_func,
|
||||
RayFunction &sync_func) {
|
||||
actors_.emplace(queue_id, actor_id);
|
||||
out_transports_.emplace(queue_id,
|
||||
std::make_shared<ray::streaming::Transport>(actor_id));
|
||||
out_transports_.emplace(queue_id, std::make_shared<ray::streaming::Transport>(
|
||||
actor_id, async_func, sync_func));
|
||||
}
|
||||
|
||||
ActorID QueueMessageHandler::GetPeerActorID(const ObjectID &queue_id) {
|
||||
@@ -164,8 +160,7 @@ bool UpstreamQueueMessageHandler::CheckQueueSync(const ObjectID &queue_id) {
|
||||
auto transport_it = GetOutTransport(queue_id);
|
||||
STREAMING_CHECK(transport_it != nullptr);
|
||||
std::shared_ptr<LocalMemoryBuffer> result_buffer = transport_it->SendForResultWithRetry(
|
||||
std::move(buffer), DownstreamQueueMessageHandler::peer_sync_function_, 10,
|
||||
COMMON_SYNC_CALL_TIMEOUTT_MS);
|
||||
std::move(buffer), 10, COMMON_SYNC_CALL_TIMEOUTT_MS);
|
||||
if (result_buffer == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,8 @@ class QueueMessageHandler {
|
||||
/// downstream queue with same queue_id, and vice versa.
|
||||
/// \param[in] queue_id queue id of current queue.
|
||||
/// \param[in] actor_id actor_id actor id of corresponded peer actor.
|
||||
void SetPeerActorID(const ObjectID &queue_id, const ActorID &actor_id);
|
||||
void SetPeerActorID(const ObjectID &queue_id, const ActorID &actor_id,
|
||||
RayFunction &async_func, RayFunction &sync_func);
|
||||
|
||||
/// Obtain the actor id of the peer actor specified by queue_id.
|
||||
/// \return actor id
|
||||
@@ -133,9 +134,6 @@ class UpstreamQueueMessageHandler : public QueueMessageHandler {
|
||||
const ActorID &actor_id);
|
||||
static std::shared_ptr<UpstreamQueueMessageHandler> GetService();
|
||||
|
||||
static RayFunction peer_sync_function_;
|
||||
static RayFunction peer_async_function_;
|
||||
|
||||
private:
|
||||
bool CheckQueueSync(const ObjectID &queue_ids);
|
||||
|
||||
@@ -170,8 +168,6 @@ class DownstreamQueueMessageHandler : public QueueMessageHandler {
|
||||
static std::shared_ptr<DownstreamQueueMessageHandler> CreateService(
|
||||
const ActorID &actor_id);
|
||||
static std::shared_ptr<DownstreamQueueMessageHandler> GetService();
|
||||
static RayFunction peer_sync_function_;
|
||||
static RayFunction peer_async_function_;
|
||||
|
||||
private:
|
||||
std::unordered_map<ObjectID, std::shared_ptr<streaming::ReaderQueue>>
|
||||
|
||||
@@ -36,17 +36,16 @@ void Transport::SendInternal(std::shared_ptr<LocalMemoryBuffer> buffer,
|
||||
}
|
||||
}
|
||||
|
||||
void Transport::Send(std::shared_ptr<LocalMemoryBuffer> buffer, RayFunction &function) {
|
||||
void Transport::Send(std::shared_ptr<LocalMemoryBuffer> buffer) {
|
||||
STREAMING_LOG(INFO) << "Transport::Send buffer size: " << buffer->Size();
|
||||
std::vector<ObjectID> return_ids;
|
||||
SendInternal(std::move(buffer), function, TASK_OPTION_RETURN_NUM_0, return_ids);
|
||||
SendInternal(std::move(buffer), async_func_, TASK_OPTION_RETURN_NUM_0, return_ids);
|
||||
}
|
||||
|
||||
std::shared_ptr<LocalMemoryBuffer> Transport::SendForResult(
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer, RayFunction &function,
|
||||
int64_t timeout_ms) {
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer, int64_t timeout_ms) {
|
||||
std::vector<ObjectID> return_ids;
|
||||
SendInternal(buffer, function, TASK_OPTION_RETURN_NUM_1, return_ids);
|
||||
SendInternal(buffer, sync_func_, TASK_OPTION_RETURN_NUM_1, return_ids);
|
||||
|
||||
std::vector<std::shared_ptr<RayObject>> results;
|
||||
Status get_st =
|
||||
@@ -73,14 +72,12 @@ std::shared_ptr<LocalMemoryBuffer> Transport::SendForResult(
|
||||
}
|
||||
|
||||
std::shared_ptr<LocalMemoryBuffer> Transport::SendForResultWithRetry(
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer, RayFunction &function, int retry_cnt,
|
||||
int64_t timeout_ms) {
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer, int retry_cnt, int64_t timeout_ms) {
|
||||
STREAMING_LOG(INFO) << "SendForResultWithRetry retry_cnt: " << retry_cnt
|
||||
<< " timeout_ms: " << timeout_ms
|
||||
<< " function: " << function.GetFunctionDescriptor()->ToString();
|
||||
<< " timeout_ms: " << timeout_ms;
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer_shared = std::move(buffer);
|
||||
for (int cnt = 0; cnt < retry_cnt; cnt++) {
|
||||
auto result = SendForResult(buffer_shared, function, timeout_ms);
|
||||
auto result = SendForResult(buffer_shared, timeout_ms);
|
||||
if (result != nullptr) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -14,34 +14,39 @@ class Transport {
|
||||
public:
|
||||
/// Construct a Transport object.
|
||||
/// \param[in] peer_actor_id actor id of peer actor.
|
||||
Transport(const ActorID &peer_actor_id)
|
||||
: worker_id_(CoreWorkerProcess::GetCoreWorker().GetWorkerID()),
|
||||
peer_actor_id_(peer_actor_id) {}
|
||||
Transport(const ActorID &peer_actor_id, RayFunction &async_func, RayFunction &sync_func)
|
||||
: peer_actor_id_(peer_actor_id), async_func_(async_func), sync_func_(sync_func) {
|
||||
STREAMING_LOG(INFO) << "Transport constructor:";
|
||||
STREAMING_LOG(INFO) << "async_func lang: " << async_func_.GetLanguage();
|
||||
STREAMING_LOG(INFO) << "async_func: "
|
||||
<< async_func_.GetFunctionDescriptor()->ToString();
|
||||
STREAMING_LOG(INFO) << "sync_func lang: " << sync_func_.GetLanguage();
|
||||
STREAMING_LOG(INFO) << "sync_func: "
|
||||
<< sync_func_.GetFunctionDescriptor()->ToString();
|
||||
}
|
||||
|
||||
virtual ~Transport() = default;
|
||||
|
||||
/// Send buffer asynchronously, peer's `function` will be called.
|
||||
/// \param[in] buffer buffer to be sent.
|
||||
/// \param[in] function the function descriptor of peer's function.
|
||||
virtual void Send(std::shared_ptr<LocalMemoryBuffer> buffer, RayFunction &function);
|
||||
virtual void Send(std::shared_ptr<LocalMemoryBuffer> buffer);
|
||||
|
||||
/// Send buffer synchronously, peer's `function` will be called, and return the peer
|
||||
/// function's return value.
|
||||
/// \param[in] buffer buffer to be sent.
|
||||
/// \param[in] function the function descriptor of peer's function.
|
||||
/// \param[in] timeout_ms max time to wait for result.
|
||||
/// \return peer function's result.
|
||||
virtual std::shared_ptr<LocalMemoryBuffer> SendForResult(
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer, RayFunction &function,
|
||||
int64_t timeout_ms);
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer, int64_t timeout_ms);
|
||||
|
||||
/// Send buffer and get result with retry.
|
||||
/// return value.
|
||||
/// \param[in] buffer buffer to be sent.
|
||||
/// \param[in] function the function descriptor of peer's function.
|
||||
/// \param[in] max retry count
|
||||
/// \param[in] timeout_ms max time to wait for result.
|
||||
/// \return peer function's result.
|
||||
std::shared_ptr<LocalMemoryBuffer> SendForResultWithRetry(
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer, RayFunction &function, int retry_cnt,
|
||||
int64_t timeout_ms);
|
||||
std::shared_ptr<LocalMemoryBuffer> buffer, int retry_cnt, int64_t timeout_ms);
|
||||
|
||||
private:
|
||||
/// Send buffer internal
|
||||
@@ -56,6 +61,8 @@ class Transport {
|
||||
private:
|
||||
WorkerID worker_id_;
|
||||
ActorID peer_actor_id_;
|
||||
RayFunction async_func_;
|
||||
RayFunction sync_func_;
|
||||
};
|
||||
} // namespace streaming
|
||||
} // namespace ray
|
||||
|
||||
Reference in New Issue
Block a user