@@ -18,18 +18,17 @@ using namespace RsyncService;
1818extern PikaServer* g_pika_server;
1919
2020const int kFlushIntervalUs = 10 * 1000 * 1000 ;
21- const int kThrottleBytesPerSecond = 300 << 20 ;
2221const int kBytesPerRequest = 4 << 20 ;
2322const int kThrottleCheckCycle = 10 ;
2423
2524namespace rsync {
2625RsyncClient::RsyncClient (const std::string& dir, const std::string& db_name, const uint32_t slot_id)
2726 : snapshot_uuid_(" " ), dir_(dir), db_name_(db_name), slot_id_(slot_id),
28- state_ (IDLE ), max_retries_(10 ), master_ip_(" " ), master_port_(0 ) {
27+ state_ (IDLE ), max_retries_(10 ), master_ip_(" " ), master_port_(0 ),
28+ parallel_num_(g_pika_conf->max_rsync_parallel_num ()) {
2929 wo_mgr_.reset (new WaitObjectManager ());
3030 client_thread_ = std::make_unique<RsyncClientThread>(3000 , 60 , wo_mgr_.get ());
31- work_threads_.resize (kMaxRsyncParallelNum );
32- throttle_.reset (new Throttle (kThrottleBytesPerSecond , kThrottleCheckCycle ));
31+ work_threads_.resize (GetParallelNum ());
3332 finished_work_cnt_.store (0 );
3433}
3534
@@ -83,13 +82,13 @@ void* RsyncClient::ThreadMain() {
8382
8483 Status s = Status::OK ();
8584 LOG (INFO ) << " RsyncClient begin to copy remote files" ;
86- std::vector<std::set<std::string> > file_vec (kMaxRsyncParallelNum );
85+ std::vector<std::set<std::string> > file_vec (GetParallelNum () );
8786 int index = 0 ;
8887 for (const auto & file : file_set_) {
89- file_vec[index++ % kMaxRsyncParallelNum ].insert (file);
88+ file_vec[index++ % GetParallelNum () ].insert (file);
9089 }
9190
92- for (int i = 0 ; i < kMaxRsyncParallelNum ; i++) {
91+ for (int i = 0 ; i < GetParallelNum () ; i++) {
9392 work_threads_[i] = std::move (std::thread (&RsyncClient::Copy, this , file_vec[i], i));
9493 }
9594
@@ -126,12 +125,12 @@ void* RsyncClient::ThreadMain() {
126125 outfile.flush ();
127126 meta_rep.clear ();
128127
129- if (finished_work_cnt_.load () == kMaxRsyncParallelNum ) {
128+ if (finished_work_cnt_.load () == GetParallelNum () ) {
130129 break ;
131130 }
132131 }
133132
134- for (int i = 0 ; i < kMaxRsyncParallelNum ; i++) {
133+ for (int i = 0 ; i < GetParallelNum () ; i++) {
135134 work_threads_[i].join ();
136135 }
137136 finished_work_cnt_.store (0 );
@@ -161,7 +160,7 @@ Status RsyncClient::CopyRemoteFile(const std::string& filename, int index) {
161160 break ;
162161 }
163162 size_t copy_file_begin_time = pstd::NowMicros ();
164- size_t count = throttle_-> ThrottledByThroughput (kBytesPerRequest );
163+ size_t count = Throttle::GetInstance (). ThrottledByThroughput (kBytesPerRequest );
165164 if (count == 0 ) {
166165 std::this_thread::sleep_for (std::chrono::milliseconds (1000 / kThrottleCheckCycle ));
167166 continue ;
@@ -200,7 +199,7 @@ Status RsyncClient::CopyRemoteFile(const std::string& filename, int index) {
200199
201200 size_t ret_count = resp->file_resp ().count ();
202201 size_t elaspe_time_us = pstd::NowMicros () - copy_file_begin_time;
203- throttle_-> ReturnUnusedThroughput (count, ret_count, elaspe_time_us);
202+ Throttle::GetInstance (). ReturnUnusedThroughput (count, ret_count, elaspe_time_us);
204203
205204 if (resp->code () != RsyncService::kOk ) {
206205 // TODO: handle different error
@@ -492,5 +491,9 @@ std::string RsyncClient::GetLocalMetaFilePath() {
492491 return db_path + kDumpMetaFileName ;
493492}
494493
494+ int RsyncClient::GetParallelNum () {
495+ return parallel_num_;
496+ }
497+
495498} // end namespace rsync
496499
0 commit comments