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

fix(shwap/bitswap): Blockstore.GetSize: getting size with no compute #3894

Merged
merged 5 commits into from
Nov 15, 2024

Conversation

Wondertan
Copy link
Member

@Wondertan Wondertan commented Oct 28, 2024

Bitswap prioritizes peers based on their active/pending work and the priority that peers set for requests(work) themselves. The prioritization happens on the Get operation of Blockstore not GetSize. However, we currently do the most expensive work in GetSize followed by Get. It is still part of the same WANT_BLOCK request(since #3813), and GetSize work is usually cached for Get to catch it. Still, the prioritization makes it so that the time between GetSize and Get can be pretty long, inducing cache misses and redoing the same work again, which is confirmed by profiles. Also, doing the expensive part in GetSize avoids Bitswap server's rate limiting.

All this brings the need to make GetSize as lightweight as possible, leaving actual proof computed to Get. This PR achieves this by defining a constant max block size for every type block.


🎱 mb blonks certified

@Wondertan Wondertan added the kind:fix Attached to bug-fixing PRs label Oct 28, 2024
@Wondertan Wondertan self-assigned this Oct 28, 2024
@Wondertan Wondertan force-pushed the shwap-bitswap-get-size branch 3 times, most recently from 2bef3ec to ad5a7b5 Compare October 28, 2024 14:50
@walldiss
Copy link
Member

If GetSize is used only for prioritisation of bitswap server hanling of requests, perhaps don't really need to calculate sizes. Alternative could be to return const values depending on type of the cid and our estimate of proper priority / load of handling. For examples:

  • samples: 100
  • rows: 10000 (much heavier and less important than namespace data)
  • namespace data: 5000

This would allow us to remove the need for heavy reads to get the priority for serving of requests and will easy the pressure on cache.

@Wondertan
Copy link
Member Author

In sync, we agreed to keep the Size computation based on real blocksize to be safe. Making all sizes fixed to max block size may limit bitswap's throughput for small block sizes.

Copy link
Member

@renaynay renaynay left a comment

Choose a reason for hiding this comment

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

Do you need additional tests for this? Are the changes already covered by some test suite?

share/shwap/p2p/bitswap/sample_block.go Outdated Show resolved Hide resolved
@Wondertan
Copy link
Member Author

It is covered

walldiss
walldiss previously approved these changes Oct 31, 2024
vgonkivs
vgonkivs previously approved these changes Nov 1, 2024
@renaynay renaynay enabled auto-merge (squash) November 12, 2024 10:05
@Wondertan Wondertan disabled auto-merge November 12, 2024 10:40
@Wondertan
Copy link
Member Author

Disabling the automerge for now. I want to do another change here

@Wondertan Wondertan dismissed stale reviews from walldiss and vgonkivs via fc1e188 November 14, 2024 15:32
@Wondertan Wondertan force-pushed the shwap-bitswap-get-size branch from f5c4f4c to fc1e188 Compare November 14, 2024 15:32
@Wondertan Wondertan marked this pull request as ready for review November 14, 2024 15:32
renaynay
renaynay previously approved these changes Nov 14, 2024
Copy link
Member

@renaynay renaynay left a comment

Choose a reason for hiding this comment

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

utack

walldiss
walldiss previously approved these changes Nov 14, 2024
@Wondertan Wondertan dismissed stale reviews from walldiss and renaynay via 8c953dc November 14, 2024 17:54
@Wondertan Wondertan force-pushed the shwap-bitswap-get-size branch from fc1e188 to 8c953dc Compare November 14, 2024 17:54
@Wondertan Wondertan force-pushed the shwap-bitswap-get-size branch from e32030b to 8fc2000 Compare November 14, 2024 18:06
@Wondertan Wondertan enabled auto-merge (squash) November 14, 2024 18:08
@Wondertan Wondertan merged commit 24ba6da into main Nov 15, 2024
31 checks passed
@Wondertan Wondertan deleted the shwap-bitswap-get-size branch November 15, 2024 04:26
Wondertan added a commit that referenced this pull request Nov 15, 2024
…3894)

Bitswap prioritizes peers based on their active/pending work and the priority that peers set for requests(work) themselves. The prioritization happens on the `Get` operation of `Blockstore` not `GetSize`. However, we currently do the most expensive work in `GetSize` followed by `Get`. It is still part of the same WANT_BLOCK request(since #3813), and `GetSize` work is usually cached for `Get` to catch it. Still, the prioritization makes it so that the time between `GetSize` and `Get` can be pretty long, inducing cache misses and redoing the same work again, which is confirmed by profiles. Also, doing the expensive part in `GetSize` avoids Bitswap server's rate limiting. 

All this brings the need to make `GetSize` as lightweight as possible, leaving actual proof computed to `Get`. This PR achieves this by defining a constant max block size for every type block.

--- 

🎱 mb blonks certified
Wondertan added a commit that referenced this pull request Nov 15, 2024
…3894)

Bitswap prioritizes peers based on their active/pending work and the priority that peers set for requests(work) themselves. The prioritization happens on the `Get` operation of `Blockstore` not `GetSize`. However, we currently do the most expensive work in `GetSize` followed by `Get`. It is still part of the same WANT_BLOCK request(since #3813), and `GetSize` work is usually cached for `Get` to catch it. Still, the prioritization makes it so that the time between `GetSize` and `Get` can be pretty long, inducing cache misses and redoing the same work again, which is confirmed by profiles. Also, doing the expensive part in `GetSize` avoids Bitswap server's rate limiting. 

All this brings the need to make `GetSize` as lightweight as possible, leaving actual proof computed to `Get`. This PR achieves this by defining a constant max block size for every type block.

--- 

🎱 mb blonks certified
Wondertan added a commit that referenced this pull request Nov 15, 2024
…3894)

Bitswap prioritizes peers based on their active/pending work and the priority that peers set for requests(work) themselves. The prioritization happens on the `Get` operation of `Blockstore` not `GetSize`. However, we currently do the most expensive work in `GetSize` followed by `Get`. It is still part of the same WANT_BLOCK request(since #3813), and `GetSize` work is usually cached for `Get` to catch it. Still, the prioritization makes it so that the time between `GetSize` and `Get` can be pretty long, inducing cache misses and redoing the same work again, which is confirmed by profiles. Also, doing the expensive part in `GetSize` avoids Bitswap server's rate limiting. 

All this brings the need to make `GetSize` as lightweight as possible, leaving actual proof computed to `Get`. This PR achieves this by defining a constant max block size for every type block.

--- 

🎱 mb blonks certified
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:fix Attached to bug-fixing PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants