-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
batch MsgAppend entries #179
Conversation
Thanks @Sch00lb0y I am looking forward to your benchmark results :-) |
@siddontang
|
Awesome improvements @Sch00lb0y ! |
The rest LGTM! :) Thanks so much for this contribution. |
PTAL @BusyJay |
I don't think batch policy implemented here is involved in the posted benchmark result. Can you add a flag to make this feature be able to be opted out when necessary? |
Hi @BusyJay , Thanks for pointing it out. Even, I felt the same. cuz it showing different number for every run. That's why I ran cargo clean and made those results.
flag as in option like |
Yes. So that if the optimization doesn't perform as expected, user can still have a choice. |
I have addressed your suggestions. |
Please fix the conflict. |
@@ -4110,3 +4111,22 @@ fn test_new_raft_with_bad_config_errors() { | |||
let raft = Raft::new(&invalid_config, new_storage()); | |||
assert!(raft.is_err()) | |||
} | |||
// tests whether MsgAppend are batched |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a blank line above.
src/raft.rs
Outdated
batched_entries.append(ents); | ||
msg.set_entries(RepeatedField::from_vec(batched_entries)); | ||
is_empty = msg.get_entries().is_empty(); | ||
if !is_empty { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should break when target message is found.
- add test for msg append batching Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
@BusyJay conflict resolved and added those changes |
Labelling this DNM since it's close to merge and we're about to release #182. This will be part of 0.6.0 |
LGTM |
src/raft.rs
Outdated
let mut last_idx = 0; | ||
let mut is_empty = true; | ||
for msg in &mut self.msgs { | ||
if msg.get_log_term() == term |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different log term can be sent in the same message.
src/raft.rs
Outdated
// will append the entries to the existing MsgAppend | ||
let mut is_batched = false; | ||
let mut last_idx = 0; | ||
let mut is_empty = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last_idx != 0
indicates it's not empty.
src/raft.rs
Outdated
let mut batched_entries = msg.take_entries().into_vec(); | ||
batched_entries.append(ents); | ||
msg.set_entries(RepeatedField::from_vec(batched_entries)); | ||
is_empty = msg.get_entries().is_empty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check if ents
is empty instead.
src/raft.rs
Outdated
msg.set_index(pr.next_idx - 1); | ||
msg.set_commit(self.raft_log.committed); | ||
let mut batched_entries = msg.take_entries().into_vec(); | ||
batched_entries.append(ents); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if logs in origin msg and in ents are not continuous?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will that case come? (sorry if I've asked stupid question :( )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, follower can reject the leader's MsgAppend
to make it reset next_index
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it that case should I discard the previous ents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. For simplicity, you can also just give up batching in that case.
- add test to assert non continuous entries Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
@BusyJay I've made those changes and added a necessary assertion for non-continuous entries in the test case. Please have a look Thanks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rest LGTM
src/raft.rs
Outdated
"{} is sending append in unhandled state {:?}", | ||
self.tag, pr.state | ||
), | ||
msg.set_index(pr.next_idx - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not update index anymore. Seems missing a case to cover it.
src/util.rs
Outdated
pub fn is_continuous_ents(msg: &Message, ents: &[Entry]) -> bool { | ||
if !msg.get_entries().is_empty() && !ents.is_empty() { | ||
let expected_next_idx = msg.get_entries().last().unwrap().get_index() + 1; | ||
if expected_next_idx != ents.first().unwrap().get_index() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean return expected_next_idx == ents.first().unwrap().get_index()
?
- add assertion to check index - refactor is_continuous util Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
@BusyJay done :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
Thanks so much @Sch00lb0y :) Really appreciate your continued improvements! |
#18
entries will be appended if there is an existing receiver MsgAppend message.
let me know if anything needs to be added.
Signed-off-by: balaji [email protected]