Skip to content

p2p: cache compact block message to use for low bandwidth CMPCT_BLOCK - #26755

Closed
andrewtoth wants to merge 2 commits into
bitcoin:masterfrom
andrewtoth:cache-cmpctblk-msg
Closed

andrewtoth wants to merge 2 commits into
bitcoin:masterfrom
andrewtoth:cache-cmpctblk-msg

Conversation

@andrewtoth

@andrewtoth andrewtoth commented Dec 26, 2022 •

Copy link
Copy Markdown
Contributor

Follow-up from #23880 (comment).

This stores the lazy serialized compact block message future for the last seen block, rather than a shared pointer to the compact block itself. Then we don't have to reserialize the message for any incoming CMPCTBLOCK messages from low-bandwidth peers.

It was mentioned there was a speed savings of 25% using this method for sending to high-bandwidth peers #23880 (comment). I've included benchmarks which seems to be an even higher speedup.

ns/op op/s err% ins/op cyc/op IPC bra/op miss% total benchmark
38,462.08 25,999.63 0.3% 150,324.88 84,927.50 1.770 34,126.12 0.1% 0.01 SerializeNetMsg
ns/op op/s err% ins/op cyc/op IPC bra/op miss% total benchmark
616.47 1,622,135.41 0.9% 796.14 1,359.27 0.586 177.03 0.0% 0.01 CacheSerializeNetMsg

@DrahtBot

DrahtBot commented Dec 26, 2022 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26326 (net: don't lock cs_main while reading blocks in net processing by andrewtoth)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Comment thread src/bench/checkblock.cpp
)};

bench.run([&] {
CSerializedNetMsg msg{lazy_ser.get().Copy()};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure how useful this is. Won't this massively elevate the duration of the first call compared to all following ones?

The speed-up I reported in #23880 (comment) is obviously dependent on the number of peers you send the message to. If there is only one peer, it will be slower, because the duration is Ser+Copy*1, which is more work than just Ser*1. However with sufficient peers N, there is a speed-up because Ser+Copy*N is faster than Ser*N.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm I suppose a better benchmark would be time it takes to copy to see what N needs to be for this optimization to make sense. I was making the assumption here that Copy is always faster than Ser, so if there's at least one high bandwidth peer we relayed too already then it makes sense to just Copy for any low bandwidth requests that come in rather than Ser.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the confusion is that this PR was changing the first low bandwidth response to use a lazy serializer and copy. This is actually using a copy of the same lazy future that is used for the high bandwidth peers. So as long as there's at least one high bandwidth peer then this optimization makes sense because the serialization will already have been done.

@andrewtoth

Copy link
Copy Markdown
Contributor Author

Benefit doesn't seem to be worth the change here.

@andrewtoth andrewtoth closed this Dec 28, 2022
@andrewtoth
andrewtoth deleted the cache-cmpctblk-msg branch December 28, 2022 18:19
@bitcoin bitcoin locked and limited conversation to collaborators Dec 28, 2023
davidgumberg added a commit to davidgumberg/bitcoin that referenced this pull request Jan 7, 2026
This commit is drawn from the closed bitcoin#26755.
(bitcoin#26755)

This also changes `std::launch::deferred` to `std::launch::async` since
we are likely going to use this result very soon if someone has
requested HB blocks from us, and if no one has, then performance here is
not that critical.

Co-authored-by: Andrew Toth <[email protected]
davidgumberg added a commit to davidgumberg/bitcoin that referenced this pull request Jul 14, 2026
This commit is drawn from the closed bitcoin#26755.
(bitcoin#26755)

This also changes `std::launch::deferred` to `std::launch::async` since
we are likely going to use this result very soon if someone has
requested HB blocks from us, and if no one has, then performance here is
not that critical.

Co-authored-by: Andrew Toth <[email protected]
davidgumberg added a commit to davidgumberg/bitcoin that referenced this pull request Aug 4, 2026
This commit is drawn from the closed bitcoin#26755.
(bitcoin#26755)

This also changes `std::launch::deferred` to `std::launch::async` since
we are likely going to use this result very soon if someone has
requested HB blocks from us, and if no one has, then performance here is
not that critical.

Co-authored-by: Andrew Toth <[email protected]
davidgumberg added a commit to davidgumberg/bitcoin that referenced this pull request Oct 9, 2026
This commit is drawn from the closed bitcoin#26755.
(bitcoin#26755)

This also changes `std::launch::deferred` to `std::launch::async` since
we are likely going to use this result very soon if someone has
requested HB blocks from us, and if no one has, then performance here is
not that critical.

Co-authored-by: Andrew Toth <[email protected]
davidgumberg added a commit to davidgumberg/bitcoin that referenced this pull request Oct 18, 2026
This commit is drawn from the closed bitcoin#26755.
(bitcoin#26755)

This also changes `std::launch::deferred` to `std::launch::async` since
we are likely going to use this result very soon if someone has
requested HB blocks from us, and if no one has, then performance here is
not that critical.

Co-authored-by: Andrew Toth <[email protected]
davidgumberg added a commit to davidgumberg/bitcoin that referenced this pull request Nov 6, 2026
This commit is drawn from the closed bitcoin#26755.
(bitcoin#26755)

This also changes `std::launch::deferred` to `std::launch::async` since
we are likely going to use this result very soon if someone has
requested HB blocks from us, and if no one has, then performance here is
not that critical.

Co-authored-by: Andrew Toth <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants