-
Notifications
You must be signed in to change notification settings - Fork 289
Set a limit on max number of concurrent outbound http requests #3285
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
Merged
+144
−32
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ impl spin_http::Host for crate::InstanceState { | |
| if !req.params.is_empty() { | ||
| tracing::warn!("HTTP params field is deprecated"); | ||
| } | ||
|
|
||
| let req_url = if !uri.starts_with('/') { | ||
| // Absolute URI | ||
| let is_allowed = self | ||
|
|
@@ -92,13 +91,21 @@ impl spin_http::Host for crate::InstanceState { | |
| // in a single component execution | ||
| let client = self.spin_http_client.get_or_insert_with(|| { | ||
| let mut builder = reqwest::Client::builder(); | ||
| if !self.connection_pooling { | ||
| if !self.connection_pooling_enabled { | ||
| builder = builder.pool_max_idle_per_host(0); | ||
| } | ||
| builder.build().unwrap() | ||
| }); | ||
|
|
||
| // If we're limiting concurrent outbound requests, acquire a permit | ||
| // Note: since we don't have access to the underlying connection, we can only | ||
| // limit the number of concurrent requests, not connections. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Teeechnically we probably could via https://docs.rs/reqwest/0.12.24/reqwest/struct.ClientBuilder.html#method.connector_layer but given that this interface is effectively deprecated this seems fine. |
||
| let permit = match &self.concurrent_outbound_connections_semaphore { | ||
| Some(s) => s.acquire().await.ok(), | ||
| None => None, | ||
| }; | ||
| let resp = client.execute(req).await.map_err(log_reqwest_error)?; | ||
| drop(permit); | ||
|
|
||
| tracing::trace!("Returning response from outbound request to {req_url}"); | ||
| span.record("http.response.status_code", resp.status().as_u16()); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not a huge deal since we're talking about rather large limits but I don't understand this interpretation. I would expect "0 concurrent connections" to mean "you can't ever connect" (which should perhaps be invalid).
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.
I guess I have a different interpretation. A concurrent request is by definition one that is happening during another request. 0 concurrent requests would therefore mean "no requests happening at the same time" not "no requests at all". I think we should just pick which ever interpretation is most convenient and use that.
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.
How many requests are involved in "2 concurrent requests"?
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.
That is strictly true, but I think that doing the +1 makes everything else more confusing. The first request becomes concurrent once there is two total requests.
I'd vote for removing the
+ 1