-
Notifications
You must be signed in to change notification settings - Fork 261
Limit concurrent HTTP requests #922
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
base: main
Are you sure you want to change the base?
Conversation
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. (Because this pull request was imported automatically, there will not be any future comments.) |
cc @cormacrelf |
d9909c9
to
57a8fac
Compare
Reworked this to reduce the boilerplate and ensure the semaphore permit is held until the response is fully consumed. Hopefully that doesn't confuse the import? |
03cf79a
to
fcba6c4
Compare
fcba6c4
to
9786a5c
Compare
.inspect(move |_| { | ||
// Ensure we keep a concurrent request permit alive until the stream is consumed | ||
let _guard = &semaphore_guard; | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little cheeky and might be clearer as a stream transformer struct, but that would probably take about 4x as much code. Let me know if that'd be preferred.
When building a non-trivial project with third-party dependencies fetched via
http_archive
or similar, e.g. from reindeer in non-vendored mode, buck2 can generate extremely large numbers of outgoing HTTP requests. Hyper does not enforce any limits itself, happily expanding its connection pool with every additional concurrent request. This can cause the remote HTTP server to reject requests, and even lead to buck2 itself failing with "too many open files" errors.Larger numbers of concurrent requests have rapidly diminishing returns, so while there's no obviously correct limit, any smallish number should improve behavior in most cases. It may even improve total throughput by reducing contention for network bandwidth.
See also discussion in facebookincubator/reindeer#46.