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

Read messages before applying quota to avoid mplex backpressure issues #4697

Merged
merged 5 commits into from
Jun 8, 2023

Conversation

Menduist
Copy link
Contributor

@Menduist Menduist commented Mar 6, 2023

With mplex, the backpressure is at the connection level, and not the stream level.
It means that if a received message is not read, the entire connection will get blocked

This PR modifies the quota to be applied after reading the message, and not before, since doing so will pause the entire connection
The number of simultaneous requests is still limited by libp2p

cc @arnetheduck

@Menduist Menduist changed the title Apply global quota after reading messages Read messages before applying quota to avoid mplex backpressure issues Mar 6, 2023
@Menduist Menduist marked this pull request as draft March 6, 2023 15:20
@github-actions
Copy link

github-actions bot commented Mar 6, 2023

Unit Test Results

         9 files  ±0    1 065 suites  ±0   35m 53s ⏱️ -31s
  3 554 tests ±0    3 317 ✔️ ±0  237 💤 ±0  0 ±0 
15 419 runs  ±0  15 154 ✔️ ±0  265 💤 ±0  0 ±0 

Results for commit 32bfa4f. ± Comparison against base commit 8771e91.

# limited by libp2p), this will naturally adapt them to the available
# quota.

awaitQuota(peer, libp2pRequestCost, shortProtocolId(protocolId))
Copy link
Member

Choose a reason for hiding this comment

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

hm, it's ok to read before quota, but we must count failures also - ie receiving an invalid message should also count / be slowed down - this protects against buggy clients tight-looping an invalid request

Copy link
Member

Choose a reason for hiding this comment

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

ping @Menduist what shall we do with this 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.

Sorry forgot about it, I'll find a way to take your comment into account and we should merge it

@Menduist Menduist marked this pull request as ready for review June 8, 2023 09:04
@Menduist
Copy link
Contributor Author

Menduist commented Jun 8, 2023

A possible issue with this PR is that we may hold 10 "request object" in memory while we wait for quota, whereas before, in this scenario, the data would have been queued in the kernel instead (so not decompressed etc)
Not sure if this can cause trouble, I would guess most request objects are quite small, but I'll let someone with better knowledge of the req/response domain weigh in

@arnetheduck
Copy link
Member

Not sure if this can cause trouble, I would guess most request objects are quite small, but I'll let someone with better knowledge of the req/response domain weigh in

this is fine since the number of concurrent requests is reasonably capped - that said, there's an old issue open about computing the maximum size of an SSZ message based on its limits which would further cap the damage - it's already possible for fixed-size messages (which most requests are) so it would be good to check that as well.

cc @zah

@arnetheduck
Copy link
Member

A possible issue with this PR

@Menduist in the meantime, this deserves an explanatory comment in the code

# limited by libp2p), this will naturally adapt them to the available
# quota.

awaitQuota(peer, libp2pRequestCost, shortProtocolId(protocolId))
Copy link
Member

Choose a reason for hiding this comment

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

also, we need an explanation here why it's done in finally, which is .. unusual

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@arnetheduck arnetheduck enabled auto-merge (squash) June 8, 2023 13:40
@arnetheduck arnetheduck merged commit 46a1263 into unstable Jun 8, 2023
@arnetheduck arnetheduck deleted the quotaafterread branch June 8, 2023 14:20
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.

2 participants