Skip to content

Commit 95f20b9

Browse files
committed
add comment and refine code
1 parent f9a65b0 commit 95f20b9

File tree

5 files changed

+56
-25
lines changed

5 files changed

+56
-25
lines changed

demo/quick_start/cluster/pserver.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ source "$bin_dir/env.sh"
1919
paddle pserver \
2020
--nics=`get_nics` \
2121
--port=7164 \
22-
--ports_num=2 \
22+
--ports_num=1 \
2323
--ports_num_for_sparse=1 \
2424
--num_gradient_servers=1 \
2525
--comment="paddle_pserver" \

paddle/pserver/PServerUtil.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,11 @@ limitations under the License. */
1616

1717
namespace paddle {
1818

19-
ParameterServerConfig* PServerUtil::initConfig() {
20-
ParameterServerConfig* config = new ParameterServerConfig();
21-
config->set_nics(FLAGS_nics);
22-
config->set_port(FLAGS_port);
23-
config->set_ports_num(FLAGS_ports_num);
24-
config->set_rdma_tcp(FLAGS_rdma_tcp);
25-
return config;
26-
}
27-
28-
PServerUtil* PServerUtil::create() {
29-
auto& pServerConfig = *paddle::PServerUtil::initConfig();
30-
return PServerUtil::create(pServerConfig);
31-
}
32-
33-
PServerUtil* PServerUtil::create(const ParameterServerConfig& config) {
34-
return new PServerUtil(config);
35-
}
36-
3719
PServerUtil::PServerUtil(const ParameterServerConfig& config) {
3820
// round robin to load balance RDMA server ENGINE
3921
std::vector<std::string> devices;
4022
int rdmaCpu = 0;
4123
int onlineCpus = rdma::numCpus();
42-
;
4324
int numPorts = config.ports_num() + config.ports_num_for_sparse();
4425

4526
if (FLAGS_nics.empty()) {
@@ -78,6 +59,24 @@ PServerUtil::PServerUtil(const ParameterServerConfig& config) {
7859

7960
PServerUtil::~PServerUtil() { this->join(); }
8061

62+
ParameterServerConfig* PServerUtil::initConfig() {
63+
ParameterServerConfig* config = new ParameterServerConfig();
64+
config->set_nics(FLAGS_nics);
65+
config->set_port(FLAGS_port);
66+
config->set_ports_num(FLAGS_ports_num);
67+
config->set_rdma_tcp(FLAGS_rdma_tcp);
68+
return config;
69+
}
70+
71+
PServerUtil* PServerUtil::createWithGflags() {
72+
auto& pServerConfig = *paddle::PServerUtil::initConfig();
73+
return create(pServerConfig);
74+
}
75+
76+
PServerUtil* PServerUtil::create(const ParameterServerConfig& config) {
77+
return new PServerUtil(config);
78+
}
79+
8180
void PServerUtil::start() {
8281
LOG(INFO) << "pserver sizes : " << pservers_.size();
8382
int i = 0;

paddle/pserver/PServerUtil.h

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,47 @@ namespace paddle {
2424
class PServerUtil {
2525
public:
2626
DISABLE_COPY(PServerUtil);
27-
static PServerUtil* create();
28-
static PServerUtil* create(const ParameterServerConfig& config);
27+
28+
/**
29+
* @brief Ctor, Create a PServerUtil from ParameterServerConfig.
30+
*/
2931
explicit PServerUtil(const ParameterServerConfig& config);
32+
33+
/**
34+
* @brief Dtor.
35+
*/
3036
~PServerUtil();
31-
static ParameterServerConfig* initConfig();
37+
38+
/**
39+
* @brief create PServerUtil from gflags, this is used for
40+
* compatibility with the old usage of configuration by gflags.
41+
*/
42+
static PServerUtil* createWithGflags();
43+
44+
/**
45+
* @brief create PServerUtil with ParameterServerConfig, remove gflags
46+
* from ParameterServer. Init all pservers thread according to the config.
47+
*/
48+
static PServerUtil* create(const ParameterServerConfig& config);
49+
50+
/**
51+
* @brief start all pserver thread in this PServerUtil.
52+
*/
3253
void start();
54+
55+
/**
56+
* @brief join and wait for all pserver thread in this PServerUtil.
57+
*/
3358
void join();
3459

3560
private:
3661
std::vector<std::shared_ptr<ParameterServer2>> pservers_;
62+
63+
/**
64+
* @brief create ParameterServerConfig from gflags, this is used for
65+
* compatibility with the old usage of configuration by gflags.
66+
*/
67+
static ParameterServerConfig* initConfig();
3768
};
3869

3970
} // namespace paddle

paddle/pserver/ParameterServer2Main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ using namespace paddle; // NOLINT
2121
int main(int argc, char** argv) {
2222
initMain(argc, argv);
2323

24-
std::unique_ptr<PServerUtil> pServerPtr(paddle::PServerUtil::create());
24+
std::unique_ptr<PServerUtil> pServerPtr(
25+
paddle::PServerUtil::createWithGflags());
2526
pServerPtr->start();
2627
pServerPtr->join();
2728

paddle/trainer/TrainerMain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main(int argc, char** argv) {
3838
initPython(argc, argv);
3939

4040
if (FLAGS_start_pserver) {
41-
PServerUtil* pServerUtil = paddle::PServerUtil::create();
41+
PServerUtil* pServerUtil = paddle::PServerUtil::createWithGflags();
4242
pServerUtil->start();
4343
}
4444
Trainer trainer;

0 commit comments

Comments
 (0)