Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update last_common_header only in find_blocks_to_fetch #2081

Merged
merged 10 commits into from
Jun 22, 2020

Conversation

keroro520
Copy link
Contributor

@keroro520 keroro520 commented May 18, 2020

@keroro520 keroro520 requested review from a team and doitian May 18, 2020 03:48
@keroro520 keroro520 changed the title feat: update last_common_header only in find_blocks_to_fetchœ feat: update last_common_header only in find_blocks_to_fetch May 18, 2020
@doitian doitian requested a review from driftluo May 18, 2020 07:46
@doitian
Copy link
Member

doitian commented May 19, 2020

Is there any benchmark to show the differences among the three different strategies?

  1. Update last common immediately for all peers whenever the node receives a new block.
  2. Lazy update only in fetch
  3. A hybrid solution. Do some quick updates in 1 and use 2 as a fallback.

@quake
Copy link
Member

quake commented May 19, 2020

@keroro520 CI failed, may need to rebase, please check the log

@keroro520
Copy link
Contributor Author

keroro520 commented May 23, 2020

Is there any benchmark to show the differences among the three different strategies?

  1. Update last common immediately for all peers whenever the node receives a new block.
  2. Lazy update only in fetch
  3. A hybrid solution. Do some quick updates in 1 and use 2 as a fallback.

No benchmark for this change, as I don't think it is necessary to bench it.

  1. In my opinion, the strategy to update last_common_header cause a very small effect on the sync-performance. It's hard to make this kind of benchmark.

  2. "Update last common immediately" is prone to error. For example, when chain.process_block returns Ok(false) because the given block is already stored at before, but the original code will still update the last_common_header.

  3. "Lazy update only in fetch" is more simple and easy to ensure the correctness.

driftluo
driftluo previously approved these changes May 28, 2020
Copy link
Collaborator

@driftluo driftluo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Differences caused by delayed update common:

  1. There may be a small increase in the consumption of get_ancester
  2. Unify all update points, and can unify the common point of each peer relatively quickly. If there is a stuck or a large number of orphan block updates, this is the advantage

@doitian
Copy link
Member

doitian commented Jun 12, 2020

benchmark

@nervos-bot-user
Copy link
Collaborator

Benchmark Result

  • TPS: 345.21
  • Samples Count: 50
  • CKB Version: e99b150
  • Instance Type: c5.xlarge
  • Instances Count: 3
  • Bench Type: 2in2out
  • CKB Logger Filter: info,ckb=debug

@@ -9,7 +9,7 @@ use ckb_types::{packed, prelude::*};
pub struct BlockProcess<'a> {
message: packed::SendBlockReader<'a>,
synchronizer: &'a Synchronizer,
peer: PeerIndex,
_peer: PeerIndex,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above two code has changed/removed, peer is unnecessary for BlockProcess.
However, removing peer from BlockProcess would affect many test codes. I just change to the field name to _peer to disable the compiler noise.


// NOTE: Never use `LruCache` as container. We have to ensure synchronizing between
// orphan_block_pool and block_status_map, but `LruCache` would prune old items implicitly.
#[derive(Default)]
pub struct OrphanBlockPool {
blocks: RwLock<HashMap<ParentHash, HashMap<packed::Byte32, OrphanBlock>>>,
blocks: RwLock<HashMap<ParentHash, HashMap<packed::Byte32, core::BlockView>>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How this change is related to the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is about reverting #1997 .

#1997 records peer-index in OrphanBlockPool so that we can update the peer-state once accepting an orphan block.
#1997 is required originally, which we update the corresponding peer's peer.last_common_header every time accepting a new block.

This PR changes the way to update peer.last_common_header. We don't need to record peer-index inside OrphanBlockPool, hence I remove it.

@keroro520
Copy link
Contributor Author

bors r=quake,doitian

@bors
Copy link
Contributor

bors bot commented Jun 22, 2020

Build succeeded:

  • continuous-integration/travis-ci/push

@bors bors bot merged commit a645db7 into nervosnetwork:develop Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants