Repository navigation
Optimize consensus loop - #5728
Conversation
3464252 to
a7799ac
Compare
| license = "Apache-2.0" | ||
| edition = "2021" | ||
| rust-version = "1.77" | ||
| rust-version = "1.80" |
There was a problem hiding this comment.
Required for div_duration_f32 that I now use in consensus loop.
timvisee
left a comment
There was a problem hiding this comment.
I did go through this, but I find it quite hard to keep track on what all the changes do exactly.
I agree that testing this on choas tesing for a while is a good idea, just to be sure there's no obvious problem. We can start testing after releasing 1.13.
b4f5ba1 to
19c80dd
Compare
timvisee
left a comment
There was a problem hiding this comment.
There's a lot going on here. Though I don't see any obvious problems I'm not confident I got all possible edge cases here in these changes.
As said before, let's test this on chaos testing for a while. We can merge this once we've released 1.13.1 which will be in one or two days.
19c80dd to
fda28ee
Compare
|
Rebased on |
This PR fixes two non-critical performance bugs in consensus loop:
Node that receives constant stream of consensus updates will trigger excessive Raft elections
Our consensus loop is structured in the following way:
on_readyThere's a corner case with this loop structure:
on_readyfor all these messages.on_readywill often take more time, than election timeout.To fix this issue, we check if any new Raft messages were received since last iteration of the loop, and limit the number of times we tick Raft node.
From my tests, Raft crate is not super reliant on ticks: it works even if you never tick any node, as long as you established a leader and all nodes are online, so this should be safe.
`try_sync_local_state` is not always triggered reliably
While working on the first bug in the PR, I discovered that sometimes the
try_sync_local_statemight not be triggered for multiple seconds on a node.try_sync_local_state, if during an iteration of consensus loop, no messages were received and noReadystate produced by Raft node.Readystate is produced to send a heartbeat-response message.on_readywould take a bit too long to process, or due to timeouts not being perfectly precise), and so for multipe iterations of the loop, each iteration would receive a message and/or produceReadystate, andtry_sync_local_statemight not be triggered for seconds.To fix this, I reworked how we trigger `try_sync_local_state:
on_readynow returnsis_idleflag.on_readyRaft state was not updated. E.g., no new entries appended to WAL, no entries committed, no Raft snapshot applied. The only idle operation duringon_readyis sending outgoing Raft messages.try_sync_local_state, if the node was idle for a few consecutive iterations of consensus loop.This way, we can reliably detect when node caught up with consensus (and heartbeats don't affect this check).
All Submissions:
devbranch. Did you create your branch fromdev?New Feature Submissions:
cargo +nightly fmt --allcommand prior to submission?cargo clippy --all --all-featurescommand?Changes to Core Features: