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

Stagger Block By Range Responses #5618

Merged
merged 11 commits into from
Apr 26, 2020
Merged

Stagger Block By Range Responses #5618

merged 11 commits into from
Apr 26, 2020

Conversation

nisdas
Copy link
Member

@nisdas nisdas commented Apr 25, 2020

For context #5587.

Lighthouse peers were being constantly rate limited by prysm peers due to them request multiple batches of size 64 blocks. These requests being sent at once triggered our rate limiter. To make it easier for other clients asking for bigger batches of blocks, we instead stagger our block responses.

If the requested block range is greater than the alloted blocksPerSecond variable, we instead wait one second before sending the next batch over. This prevents prysm from being overwhelmed when serving multiple large requests at once. By spreading out the request over 10 seconds(response deadline), we prevent the rate limiter from being triggered and also allow prysm to serve large requests.

@nisdas nisdas requested a review from a team as a code owner April 25, 2020 14:57
@nisdas nisdas added the Ready For Review A pull request ready for code review label Apr 25, 2020
@nisdas nisdas requested a review from prestonvanloon April 25, 2020 15:11
@nisdas nisdas changed the title Stream Block By Range Responses Stagger Block By Range Responses Apr 25, 2020
Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

Cosmetic feedbacks and a question on magic number


r.blocksRateLimiter.Add(stream.Conn().RemotePeer().String(), int64(m.Count))
// TODO(3147): Update this with reasonable constraints.
if endSlot-startSlot > 1000 || m.Step == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

what is this 1000 magic number? should we define it at the top and use a const?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not actually sure, we have had it for as long as I can remember
@prestonvanloon any idea why its 1000 ?

Copy link
Member

Choose a reason for hiding this comment

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

There is no reason. I put 1000 because I felt that was a large range and anything more than that would be too much to fetch from the DB at once.

beacon-chain/sync/rpc_beacon_blocks_by_range.go Outdated Show resolved Hide resolved
r.blocksRateLimiter.Add(stream.Conn().RemotePeer().String(), int64(m.Count))
// TODO(3147): Update this with reasonable constraints.
if endSlot-startSlot > 1000 || m.Step == 0 {
r.writeErrorResponseToStream(responseCodeInvalidRequest, "invalid range or step", stream)
Copy link
Member

Choose a reason for hiding this comment

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

can prefine err "invalid range or step" and use it here and L81

beacon-chain/sync/rpc_beacon_blocks_by_range.go Outdated Show resolved Hide resolved
terencechain
terencechain previously approved these changes Apr 25, 2020
farazdagi
farazdagi previously approved these changes Apr 25, 2020
Copy link
Contributor

@farazdagi farazdagi left a comment

Choose a reason for hiding this comment

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

Just some cosmetic changes to comments.

beacon-chain/sync/rpc_beacon_blocks_by_range.go Outdated Show resolved Hide resolved
beacon-chain/sync/rpc_beacon_blocks_by_range.go Outdated Show resolved Hide resolved
beacon-chain/sync/rpc_beacon_blocks_by_range.go Outdated Show resolved Hide resolved
beacon-chain/sync/rpc_beacon_blocks_by_range.go Outdated Show resolved Hide resolved
Co-Authored-By: Victor Farazdagi <[email protected]>
@nisdas nisdas dismissed stale reviews from farazdagi and terencechain via a9805ce April 25, 2020 15:55
@codecov
Copy link

codecov bot commented Apr 25, 2020

Codecov Report

Merging #5618 into master will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff           @@
##           master   #5618   +/-   ##
======================================
  Coverage    1.47%   1.47%           
======================================
  Files          69      69           
  Lines        6516    6516           
======================================
  Hits           96      96           
  Misses       6411    6411           
  Partials        9       9           

@nisdas nisdas merged commit aca9691 into master Apr 26, 2020
@delete-merged-branch delete-merged-branch bot deleted the streamRespones branch April 26, 2020 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants