raft-rs icon indicating copy to clipboard operation
raft-rs copied to clipboard

Reduce heartbeat message

Open NingLin-P opened this issue 5 years ago • 9 comments

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 :

  1. when sending a MsgAppend check if the heartbeat_elapsed reach a threshold
  2. if it does reset the heartbeat_elapsed and attach the ctx on this msg if there is one

is it possible to implement and improve a bit performance ?

NingLin-P avatar Oct 29 '19 16:10 NingLin-P

Do you mean reducing the size of MsgHeartbeat or just canceling heartbeats?

Fullstop000 avatar Oct 30 '19 02:10 Fullstop000

Canceling heartbeats.

NingLin-P avatar Oct 30 '19 03:10 NingLin-P

How does a follower keep not becoming a candidate without receiving heartbeats? OTOH, what if the current leader steps down?

Fullstop000 avatar Oct 30 '19 03:10 Fullstop000

  1. 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);
            }
  1. 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.

NingLin-P avatar Oct 30 '19 04:10 NingLin-P

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.

BusyJay avatar Oct 30 '19 05:10 BusyJay

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 :).

Fullstop000 avatar Oct 30 '19 05:10 Fullstop000

Yes, what you guy said is right.

NingLin-P avatar Oct 30 '19 05:10 NingLin-P

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

Fullstop000 avatar Oct 30 '19 06:10 Fullstop000

OK, let me try.

NingLin-P avatar Oct 30 '19 06:10 NingLin-P