baidu / braft

An industrial-grade C++ implementation of RAFT consensus algorithm based on brpc, widely used inside Baidu to build highly-available distributed systems.
Apache License 2.0
3.84k stars 862 forks source link

Speeding up copying of snapshots #362

Open kishorenc opened 2 years ago

kishorenc commented 2 years ago

I've a cluster where the nodes are far apart geographically, so there is high network latency between the nodes. In such a case, I find the snapshot install from the leader to follower to be pretty slow for large datasets.

When I increase the FLAGS_raft_max_byte_count_per_rpc value, the trasfer became much faster.

  1. Are there any other flags that I can tweak to increase the speed of snapshot transfer?
  2. If a snapshot consists of multiple files, are the files transferred sequentially or parallely? Is there a way to make the file transfer parallel to max out available network bandwidth between nodes?
PFZheng commented 2 years ago

I think there is no other way to speed up snapshot transfer, the files in snapshot are transferred sequentially.

kishorenc commented 2 years ago

Thanks for the clarification. Would you accept a patch that possibly parallelized this operation?

PFZheng commented 2 years ago

Thanks for the clarification. Would you accept a patch that possibly parallelized this operation?

Of course!

kishorenc commented 1 year ago

@PFZheng

Here's a proposed approach that I want to run by you before making changes:

Please let me know if this sounds like a good approach? Also, is it okay to use std::thread -- if not, please point me to some examples in the code where threads are managed via bthread to use as reference.

kishorenc commented 1 year ago

@PFZheng

Took a stab at this but ran into concurrency issues with FileServiceImpl::get_file which seems to have trouble allowing fetching files in parallel. Specifically, we got an error here when we tried to download multiple snapshot files in-parallel:

https://github.com/baidu/braft/blob/master/src/braft/file_service.cpp#L70

Here's the rough diff of the changes we've attempted: https://github.com/baidu/braft/compare/master...krunal1313:braft:master

Any guidance here is appreciated.

cc @chenzhangyi

kishorenc commented 1 year ago

@PFZheng @chenzhangyi

I'm sorry to follow-up: I will really appreciate if you can provide any pointers here.

chenzhangyi commented 1 year ago

@kishorenc Which kind of error did you get?

kishorenc commented 1 year ago

This is the error we get with these changes.

W0123 12:03:47.506687 80182 external/com_github_brpc_braft/src/braft/snapshot.cpp:786] 
Fail to copy, error_code 22 error_msg [E22][10.13.87.194:8107][E22]Fail to read from path=/var/lib/app/state/snapshot/snapshot_00000000000000000369 filename=db_snapshot/000444.sst : 
Invalid argument writer path /var/lib/app/state/snapshot/temp

It seems like, on the remote end, multiple files cannot be accessed at the same time.