Skip to content

Commit

Permalink
Decrease rate of Raft heartbeat messages. (#3708)
Browse files Browse the repository at this point in the history
Before we used to have 20ms ticks, but they would overload the
Raft tick channel, causing "A tick missed to fire. Node blocks
too long!" logs. Etcd uses 100ms and they haven't seen those
issues. Additionally, using 100ms for ticks does not cause
proposals to slow down, because they get sent out asap and don't
rely on ticks. So, setting this to 100ms instead of 20ms is a
NOOP.

(cherry picked from commit 4b41d9c)
  • Loading branch information
danielmai committed Jul 23, 2019
1 parent 3423da8 commit a0a3ad9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions conn/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func NewNode(rc *pb.RaftContext, store *raftwal.DiskStorage) *Node {
Store: store,
Cfg: &raft.Config{
ID: rc.Id,
ElectionTick: 100, // 2s if we call Tick() every 20 ms.
HeartbeatTick: 1, // 20ms if we call Tick() every 20 ms.
ElectionTick: 20, // 2s if we call Tick() every 100 ms.
HeartbeatTick: 1, // 100ms if we call Tick() every 100 ms.
Storage: store,
MaxInflightMsgs: 256,
MaxSizePerMsg: 256 << 10, // 256 KB should allow more batching.
Expand Down
6 changes: 5 additions & 1 deletion worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,11 @@ func (n *node) Run() {
firstRun := true
var leader bool
// See also our configuration of HeartbeatTick and ElectionTick.
ticker := time.NewTicker(20 * time.Millisecond)
// Before we used to have 20ms ticks, but they would overload the Raft tick channel, causing
// "tick missed to fire" logs. Etcd uses 100ms and they haven't seen those issues.
// Additionally, using 100ms for ticks does not cause proposals to slow down, because they get
// sent out asap and don't rely on ticks. So, setting this to 100ms instead of 20ms is a NOOP.
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()

done := make(chan struct{})
Expand Down

0 comments on commit a0a3ad9

Please sign in to comment.