raft-rs
raft-rs copied to clipboard
Reduce heartbeat message
With current implement, a MsgHeartbeat
do these things:
- update( or correct ) a peer's status like commit index, StateRole, ect.
- confirm quorum for quorum check or read index request
While the MsgAppend
already do the first, and the second are also easy to done
by attach the ctx
with MsgAppend
, we can reduce MsgHeartbeat
by :
- when sending a
MsgAppend
check if theheartbeat_elapsed
reach a threshold - if it does reset the
heartbeat_elapsed
and attach thectx
on this msg if there is one
is it possible to implement and improve a bit performance ?
Do you mean reducing the size of MsgHeartbeat
or just canceling heartbeats?
Canceling heartbeats.
How does a follower keep not becoming a candidate without receiving heartbeats? OTOH, what if the current leader steps down?
- when follower received messages from leader, it reset election_elapsed:
MessageType::MsgAppend => {
self.election_elapsed = 0;
self.leader_id = m.from;
self.handle_append_entries(&m);
}
MessageType::MsgHeartbeat => {
self.election_elapsed = 0;
self.leader_id = m.from;
self.handle_heartbeat(m);
}
MessageType::MsgSnapshot => {
self.election_elapsed = 0;
self.leader_id = m.from;
self.handle_snapshot(m);
}
- if the current leader steps down, it will be handle as before.
BTW canceling heartbeats do not mean cancel all heartbeats, just reset the heartbeat_elapsed
and delay or avoid a heartbeat.
Do you mean not to send a heartbeat if an append message is sent within an heartbeat_elapsed ticks?
I think it can bring little improvement. When under high load, heartbeat message count is way too smaller than the count of message append; when group is idle, there is too few append messages that heartbeat message is always sent out. There should still be an improvement depends on the configuration of heartbeat-elapsed though.
Ok, I think I've gotten the idea you described: only sending heartbeats when there are no MsgAppend
msgs sent in a heartbeat_timeout
.
It sounds like a good idea :).
Yes, what you guy said is right.
As for implementation should be quite simple I think, you can try to just set the leader's heartbeat_elasped
to 0 when sending MsgAppend
(or MsgSnapshot
) @NingLin-P
OK, let me try.