• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "ps/core/leader_scaler.h"
18 
19 namespace mindspore {
20 namespace ps {
21 namespace core {
ScaleOutAsync(const std::shared_ptr<TcpClient> & client,const NodeManager & manager)22 void LeaderScaler::ScaleOutAsync(const std::shared_ptr<TcpClient> &client, const NodeManager &manager) {
23   MS_EXCEPTION_IF_NULL(client);
24   MS_EXCEPTION_IF_NULL(node_);
25   auto message_meta = std::make_shared<MessageMeta>();
26   MS_EXCEPTION_IF_NULL(message_meta);
27   message_meta->set_cmd(NodeCommand::SCALE_OUT);
28 
29   ScaleOutMessage scale_out_message;
30   scale_out_message.set_worker_num(manager.worker_num());
31   scale_out_message.set_server_num(manager.server_num());
32 
33   if (!node_->SendMessageSync(client, message_meta, Protos::PROTOBUF, scale_out_message.SerializeAsString().data(),
34                               scale_out_message.ByteSizeLong())) {
35     MS_LOG(WARNING) << "Send scale out timeout!";
36   }
37 
38   MS_LOG(INFO) << "The scheduler is sending scale out to workers and servers!";
39 }
40 
ScaleInAsync(const std::shared_ptr<TcpClient> & client,const NodeManager & manager,bool is_node_scale_in)41 void LeaderScaler::ScaleInAsync(const std::shared_ptr<TcpClient> &client, const NodeManager &manager,
42                                 bool is_node_scale_in) {
43   MS_EXCEPTION_IF_NULL(client);
44   MS_EXCEPTION_IF_NULL(node_);
45   auto message_meta = std::make_shared<MessageMeta>();
46   MS_EXCEPTION_IF_NULL(message_meta);
47   message_meta->set_cmd(NodeCommand::SCALE_IN);
48 
49   ScaleInMessage scale_in_message;
50   scale_in_message.set_worker_num(manager.worker_num());
51   scale_in_message.set_server_num(manager.server_num());
52   scale_in_message.set_is_node_scale_in(is_node_scale_in);
53 
54   if (!node_->SendMessageSync(client, message_meta, Protos::PROTOBUF, scale_in_message.SerializeAsString().data(),
55                               scale_in_message.ByteSizeLong())) {
56     MS_LOG(WARNING) << "Send scale in timeout!";
57   }
58 
59   MS_LOG(INFO) << "The scheduler is sending scale in to workers and servers!";
60 }
61 }  // namespace core
62 }  // namespace ps
63 }  // namespace mindspore
64