uv: seed the PRNG #197
uv: seed the PRNG #197
Conversation
Codecov Report
@@ Coverage Diff @@
## master #197 +/- ##
==========================================
- Coverage 86.84% 86.79% -0.06%
==========================================
Files 47 47
Lines 7642 7640 -2
Branches 2041 2042 +1
==========================================
- Hits 6637 6631 -6
- Misses 902 906 +4
Partials 103 103
Continue to review full report at Codecov.
|
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.
Nice catch
IIRC the tick interval should equal the heartbeat interval, which in turn should be set to 1/10 of the election timeout (e.g. 3 seconds election timeout and 300ms heartbeat/tick). See the Raft paper for some argument about the 1/10 ration being "ideal". Isn't that the case right now in dqlite? That ratio should be set in |
Yes, if that function is called the ratio is set correctly, but most of the users just use the defaults as set in https://github.com/canonical/dqlite/blob/d30467a4da514b0f7d34880926f454b28aa63f42/src/server.c#L66 There the heartbeat timeout is 500ms and the election timeout 3000ms. The random value of the election timeout is chosen between 3000ms and 6000ms by raft in that case Line 41 in 269ac8b
|
For reference, https://github.com/canonical/raft/blob/master/src/start.c#L194 is where the periodic call to the tick function is triggered, every |
Yeah indeed, checking every tick is probably sufficient, |
Maybe it would suffices to change the default heartbeat timeout to 300ms then. Apologies if that was indeed what you meant :) |
Lowering to 300ms looks like a good start indeed, it's not what I meant :-) |
The PRNG of
rand
was not seeded, causing it to be seeded with 1 every time (see https://linux.die.net/man/3/rand) depending on the implementation ofrand
on the platform, this can result in the same random sequence obtained fromrand
on all nodes, causing the election timeout to fire at the same moment for all nodes and a cluster that cannot make progress. This would be especially problematic if all nodes start up at the same time.In a future PR I also want to adapt the election timeout mechanism. At the moment, every tick we check if the random timeout has passed. But the value of the tick is quite large (in case of dqlite 500ms) and there are only so many ticks in an election timeout interval, meaning that the randomness of the election timeout is significantly reduced, potentially resulting in slow leader election and an unresponsive cluster.