mirror of
https://github.com/wassname/ray.git
synced 2026-07-27 11:26:41 +08:00
Fetch internal config from raylet (#8195)
This commit is contained in:
@@ -265,6 +265,56 @@ CoreWorker::CoreWorker(const CoreWorkerOptions &options, const WorkerID &worker_
|
||||
task_execution_service_work_(task_execution_service_),
|
||||
resource_ids_(new ResourceMappingType()),
|
||||
grpc_service_(io_service_, *this) {
|
||||
// Initialize task receivers.
|
||||
if (options_.worker_type == WorkerType::WORKER || options_.is_local_mode) {
|
||||
RAY_CHECK(options_.task_execution_callback != nullptr);
|
||||
auto execute_task =
|
||||
std::bind(&CoreWorker::ExecuteTask, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
|
||||
raylet_task_receiver_ =
|
||||
std::unique_ptr<CoreWorkerRayletTaskReceiver>(new CoreWorkerRayletTaskReceiver(
|
||||
worker_context_.GetWorkerID(), local_raylet_client_, execute_task));
|
||||
direct_task_receiver_ =
|
||||
std::unique_ptr<CoreWorkerDirectTaskReceiver>(new CoreWorkerDirectTaskReceiver(
|
||||
worker_context_, task_execution_service_, execute_task,
|
||||
[this] { return local_raylet_client_->TaskDone(); }));
|
||||
}
|
||||
|
||||
// Start RPC server after all the task receivers are properly initialized.
|
||||
core_worker_server_.RegisterService(grpc_service_);
|
||||
core_worker_server_.Run();
|
||||
|
||||
// Initialize raylet client.
|
||||
// NOTE(edoakes): the core_worker_server_ must be running before registering with
|
||||
// the raylet, as the raylet will start sending some RPC messages immediately.
|
||||
// TODO(zhijunfu): currently RayletClient would crash in its constructor if it cannot
|
||||
// connect to Raylet after a number of retries, this can be changed later
|
||||
// so that the worker (java/python .etc) can retrieve and handle the error
|
||||
// instead of crashing.
|
||||
auto grpc_client = rpc::NodeManagerWorkerClient::make(
|
||||
options_.raylet_ip_address, options_.node_manager_port, *client_call_manager_);
|
||||
ClientID local_raylet_id;
|
||||
std::unordered_map<std::string, std::string> internal_config;
|
||||
local_raylet_client_ = std::shared_ptr<raylet::RayletClient>(new raylet::RayletClient(
|
||||
io_service_, std::move(grpc_client), options_.raylet_socket, GetWorkerID(),
|
||||
(options_.worker_type == ray::WorkerType::WORKER),
|
||||
worker_context_.GetCurrentJobID(), options_.language, &local_raylet_id,
|
||||
&internal_config, options_.node_ip_address, core_worker_server_.GetPort()));
|
||||
connected_ = true;
|
||||
|
||||
// NOTE(edoakes): any initialization depending on RayConfig must happen after this line.
|
||||
RayConfig::instance().initialize(internal_config);
|
||||
|
||||
// Set our own address.
|
||||
RAY_CHECK(!local_raylet_id.IsNil());
|
||||
rpc_address_.set_ip_address(options_.node_ip_address);
|
||||
rpc_address_.set_port(core_worker_server_.GetPort());
|
||||
rpc_address_.set_raylet_id(local_raylet_id.Binary());
|
||||
rpc_address_.set_worker_id(worker_context_.GetWorkerID().Binary());
|
||||
RAY_LOG(INFO) << "Initializing worker at address: " << rpc_address_.ip_address() << ":"
|
||||
<< rpc_address_.port() << ", worker ID " << worker_context_.GetWorkerID()
|
||||
<< ", raylet " << local_raylet_id;
|
||||
|
||||
// Initialize gcs client.
|
||||
if (RayConfig::instance().gcs_service_enabled()) {
|
||||
gcs_client_ = std::make_shared<ray::gcs::ServiceBasedGcsClient>(options_.gcs_options);
|
||||
@@ -288,50 +338,6 @@ CoreWorker::CoreWorker(const CoreWorkerOptions &options, const WorkerID &worker_
|
||||
profiler_ = std::make_shared<worker::Profiler>(
|
||||
worker_context_, options_.node_ip_address, io_service_, gcs_client_);
|
||||
|
||||
// Initialize task receivers.
|
||||
if (options_.worker_type == WorkerType::WORKER || options_.is_local_mode) {
|
||||
RAY_CHECK(options_.task_execution_callback != nullptr);
|
||||
auto execute_task =
|
||||
std::bind(&CoreWorker::ExecuteTask, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
|
||||
raylet_task_receiver_ =
|
||||
std::unique_ptr<CoreWorkerRayletTaskReceiver>(new CoreWorkerRayletTaskReceiver(
|
||||
worker_context_.GetWorkerID(), local_raylet_client_, execute_task));
|
||||
direct_task_receiver_ =
|
||||
std::unique_ptr<CoreWorkerDirectTaskReceiver>(new CoreWorkerDirectTaskReceiver(
|
||||
worker_context_, task_execution_service_, execute_task,
|
||||
[this] { return local_raylet_client_->TaskDone(); }));
|
||||
}
|
||||
|
||||
// Start RPC server after all the task receivers are properly initialized.
|
||||
core_worker_server_.RegisterService(grpc_service_);
|
||||
core_worker_server_.Run();
|
||||
|
||||
// Initialize raylet client.
|
||||
// TODO(zhijunfu): currently RayletClient would crash in its constructor if it cannot
|
||||
// connect to Raylet after a number of retries, this can be changed later
|
||||
// so that the worker (java/python .etc) can retrieve and handle the error
|
||||
// instead of crashing.
|
||||
auto grpc_client = rpc::NodeManagerWorkerClient::make(
|
||||
options_.raylet_ip_address, options_.node_manager_port, *client_call_manager_);
|
||||
ClientID local_raylet_id;
|
||||
local_raylet_client_ = std::shared_ptr<raylet::RayletClient>(new raylet::RayletClient(
|
||||
io_service_, std::move(grpc_client), options_.raylet_socket, GetWorkerID(),
|
||||
(options_.worker_type == ray::WorkerType::WORKER),
|
||||
worker_context_.GetCurrentJobID(), options_.language, &local_raylet_id,
|
||||
options_.node_ip_address, core_worker_server_.GetPort()));
|
||||
connected_ = true;
|
||||
|
||||
// Set our own address.
|
||||
RAY_CHECK(!local_raylet_id.IsNil());
|
||||
rpc_address_.set_ip_address(options_.node_ip_address);
|
||||
rpc_address_.set_port(core_worker_server_.GetPort());
|
||||
rpc_address_.set_raylet_id(local_raylet_id.Binary());
|
||||
rpc_address_.set_worker_id(worker_context_.GetWorkerID().Binary());
|
||||
RAY_LOG(INFO) << "Initializing worker at address: " << rpc_address_.ip_address() << ":"
|
||||
<< rpc_address_.port() << ", worker ID " << worker_context_.GetWorkerID()
|
||||
<< ", raylet " << local_raylet_id;
|
||||
|
||||
reference_counter_ = std::make_shared<ReferenceCounter>(
|
||||
rpc_address_, RayConfig::instance().distributed_ref_counting_enabled(),
|
||||
RayConfig::instance().lineage_pinning_enabled(), [this](const rpc::Address &addr) {
|
||||
|
||||
@@ -160,6 +160,10 @@ table RegisterClientRequest {
|
||||
table RegisterClientReply {
|
||||
// GCS ClientID of the local node manager.
|
||||
raylet_id: string;
|
||||
// Keys for internal config options.
|
||||
internal_config_keys: [string];
|
||||
// Values for internal config options corresponding to keys above.
|
||||
internal_config_values: [string];
|
||||
}
|
||||
|
||||
table RegisterNodeManagerRequest {
|
||||
|
||||
@@ -1083,8 +1083,16 @@ void NodeManager::ProcessRegisterClientRequestMessage(
|
||||
const std::shared_ptr<ClientConnection> &client, const uint8_t *message_data) {
|
||||
client->Register();
|
||||
flatbuffers::FlatBufferBuilder fbb;
|
||||
auto reply =
|
||||
ray::protocol::CreateRegisterClientReply(fbb, to_flatbuf(fbb, self_node_id_));
|
||||
std::vector<std::string> internal_config_keys;
|
||||
std::vector<std::string> internal_config_values;
|
||||
for (auto kv : initial_config_.raylet_config) {
|
||||
internal_config_keys.push_back(kv.first);
|
||||
internal_config_values.push_back(kv.second);
|
||||
}
|
||||
auto reply = ray::protocol::CreateRegisterClientReply(
|
||||
fbb, to_flatbuf(fbb, self_node_id_),
|
||||
string_vec_to_flatbuf(fbb, internal_config_keys),
|
||||
string_vec_to_flatbuf(fbb, internal_config_values));
|
||||
fbb.Finish(reply);
|
||||
client->WriteMessageAsync(
|
||||
static_cast<int64_t>(protocol::MessageType::RegisterClientReply), fbb.GetSize(),
|
||||
|
||||
@@ -166,6 +166,7 @@ raylet::RayletClient::RayletClient(
|
||||
std::shared_ptr<rpc::NodeManagerWorkerClient> grpc_client,
|
||||
const std::string &raylet_socket, const WorkerID &worker_id, bool is_worker,
|
||||
const JobID &job_id, const Language &language, ClientID *raylet_id,
|
||||
std::unordered_map<std::string, std::string> *internal_config,
|
||||
const std::string &ip_address, int port)
|
||||
: grpc_client_(std::move(grpc_client)), worker_id_(worker_id), job_id_(job_id) {
|
||||
// For C++14, we could use std::make_unique
|
||||
@@ -185,6 +186,14 @@ raylet::RayletClient::RayletClient(
|
||||
RAY_CHECK_OK_PREPEND(status, "[RayletClient] Unable to register worker with raylet.");
|
||||
auto reply_message = flatbuffers::GetRoot<protocol::RegisterClientReply>(reply.get());
|
||||
*raylet_id = ClientID::FromBinary(reply_message->raylet_id()->str());
|
||||
|
||||
RAY_CHECK(internal_config);
|
||||
auto keys = reply_message->internal_config_keys();
|
||||
auto values = reply_message->internal_config_values();
|
||||
RAY_CHECK(keys->size() == values->size());
|
||||
for (size_t i = 0; i < keys->size(); i++) {
|
||||
internal_config->emplace(keys->Get(i)->str(), values->Get(i)->str());
|
||||
}
|
||||
}
|
||||
|
||||
Status raylet::RayletClient::SubmitTask(const TaskSpecification &task_spec) {
|
||||
|
||||
@@ -154,6 +154,8 @@ class RayletClient : public PinObjectsInterface,
|
||||
/// \param job_id The ID of the driver. This is non-nil if the client is a driver.
|
||||
/// \param language Language of the worker.
|
||||
/// \param raylet_id This will be populated with the local raylet's ClientID.
|
||||
/// \param internal_config This will be populated with internal config parameters
|
||||
/// provided by the raylet.
|
||||
/// \param ip_address The IP address of the worker.
|
||||
/// \param port The port that the worker will listen on for gRPC requests, if
|
||||
/// any.
|
||||
@@ -161,7 +163,9 @@ class RayletClient : public PinObjectsInterface,
|
||||
std::shared_ptr<ray::rpc::NodeManagerWorkerClient> grpc_client,
|
||||
const std::string &raylet_socket, const WorkerID &worker_id,
|
||||
bool is_worker, const JobID &job_id, const Language &language,
|
||||
ClientID *raylet_id, const std::string &ip_address, int port = -1);
|
||||
ClientID *raylet_id,
|
||||
std::unordered_map<std::string, std::string> *internal_config,
|
||||
const std::string &ip_address, int port = -1);
|
||||
|
||||
/// Connect to the raylet via grpc only.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user