forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
consensus: optimize vote and block part gossip with HasProposalBlockP…
…artMessage and random sleeps (cometbft#904) Addresses tendermint/tendermint#627 (finally!) This PR is based off cometbft#896 which added new metrics to measure duplicate votes and block parts received from peers. This PR introduces two optimizations to the consensus gossip: HasProposalBlockPartMessage and random sleeps in the fast loop in the gossip routines. Control for both were added to the config file for testing purposes, but at least the HasProposalBlockPartMessage should probably not be in the config, it should just be hardcoded active once we're happy with it. On another note, we may want to consider some changes so this can be rolled out in a non-breaking way. If I'm not mistaken since the message was added to an existing p2p channel it will be interpreted by peers on older versions as malicious. My understanding is we could just move it to a new channel to solve this so the change would be backwards compatible and nodes can roll it out progressively. The first is a new HasProposalBlockPartMessage. This follows identical logic to the HasVoteMessage. When a node receives a ProposalBlockPart, it broadcasts the HasProposalBlockPartMessage to all its peers. This informs them that they don't need to send the node the part, thus reducing the amount of redundant block parts gossiped over the network. The second change is the introduction of a random sleep in the fast loops of the gossipVote and gossipData routines. We run these routines for each peer, and when there are things to send, the routines run in a tight loop picking and sending votes or parts to send to the peer. This reduces the effectiveness of the "HasXXXMessage" mechanism since there is minimal opportunity for the peer state to be updated with when the HasXXXMessages are received before the new votes/parts are selected to be sent. Adding a small random sleep gives the reactor a chance to breath and process inbound HasXXXMessages before picking new votes/parts to send. Randomizing the sleep ensures the peers don't all sleep the same amount, which could negate its effect. Combining the new HasBlockPartMessage with the random sleep in gossipData routine results in a ~20% bandwidth reduction on BlockPart messages in 4 node and 7 node networks under load as measured in a local testnet on my laptop, as well as 4 node networks in the cloud. Larger tests are still to be conducted, but these initial results are very promising. The random sleep in gossipVote routine also results in a ~15% bandwidth reduction on Vote messages in 7 node networks as measured in a local testnet on my laptop. Again, promising, but more tests to be done. The largest consumers of bandwidth in the comet system are mempool txs, votes, and block parts. While mempool txs are not addressed here, the latter two are, and should lead to significant reductions in bandwidth usage overall. Note the addition of a new HasProposalBlockPartMessage adds minimal additional bandwidth itself as each message contains only 3 integers (one 64 bit, two 32 bit, so 16 bytes total) compared to hundreds of bytes in a block part message. This was also confirmed experimentally. Some teaser screenshots below on small local networks using the cometbft `e2e` testing system on my laptop. With and without the random sleep (upper bounded at 50ms) on a 7 node network, with no load: <img width="1426" alt="image" src="https://github.com/cometbft/cometbft/assets/2300911/816f86a7-49d7-4988-ae57-e52d9bd196f8"> The main lines visible are the bandwidth from the Vote (the larger one) and BlockPart messages. Note how both are reduced ~15% from adding the sleep (the left). The effect of the sleep on block times is negligible (they rise from 1.6 to 1.7 seconds per block in this experiment) On a 4 node network, with and without the new HasProposalBlockPartMessage and with and without the random sleep on the gossipDataRoutine: ![image](https://github.com/cometbft/cometbft/assets/2300911/70c616e9-40ff-4f6c-b3aa-fc7b5e9adb73) Ignore the spikes on the right for now, this is the system acting up under load running all 4 nodes on my laptop ... The image shows 4 experiments. The purple line is bandwidth from mempool txs (roughly the same in all experiments), the green is bandwidth from block part messages (what we're focusing on). The experiments, and the approximate block part bandwidth when it first flattens out, are: 1. has block parts, sleep (680k) 2. no has block parts, sleep (830k) 3. has block parts, no sleep (730k) 4. no has block parts, no sleep (870k) The last experiment is the current baseline. Adding the sleep alone without the new message type (2nd experiment) has some minimal impact (870 -> 830). Adding just the new message type without the sleep (3rd experiment) has more significant impact (870 -> 730). But adding both together (1st experiiment) has the most significant impact (870->680), a reduction of ~20%. While we've done some preliminary experiments here, we still need to do larger experiments on cloud deployments, as well as writing some actual tests :) --- - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments
- Loading branch information
Showing
16 changed files
with
611 additions
and
152 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
.changelog/v0.38.0/improvements/896-consensus-metric-duplicates.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- `[consensus]` New metrics (counters) to track duplicate votes and block parts. | ||
([\#896](https://github.com/cometbft/cometbft/pull/896)) |
6 changes: 6 additions & 0 deletions
6
.changelog/v0.38.0/improvements/904-gossip-sleep-had-block-part.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- `[consensus]` Optimize vote and block part gossip with new message `HasProposalBlockPartMessage`, | ||
which is similar to `HasVoteMessage`; and random sleep in the loop broadcasting those messages. | ||
The sleep can be configured with new config `peer_gossip_intraloop_sleep_duration`, which is set to 0 | ||
by default as this is experimental. | ||
Our scale tests show substantial bandwith improvement with a value of 50 ms. | ||
([\#904](https://github.com/cometbft/cometbft/pull/904)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.