-
Notifications
You must be signed in to change notification settings - Fork 91
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
Users/oakeredolu/throttlehttpclient #872
base: main
Are you sure you want to change the base?
Conversation
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
Codecov Report
@@ Coverage Diff @@
## main #872 +/- ##
=======================================
- Coverage 77.5% 74.8% -2.8%
=======================================
Files 235 235
Lines 9953 9960 +7
Branches 0 975 +975
=======================================
- Hits 7719 7455 -264
+ Misses 2234 2232 -2
- Partials 0 273 +273
|
this.logger.LogInformation("Getting Python data from {Uri}", uri); | ||
using var request = new HttpRequestMessage(HttpMethod.Get, uri); | ||
request.Headers.UserAgent.Add(ProductValue); | ||
request.Headers.UserAgent.Add(CommentValue); | ||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.pypi.simple.v1+json")); | ||
var response = await HttpClient.SendAsync(request); | ||
this.semaphore.Release(); |
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.
We should do this within a try-catch-finally block which throws the exception again but releases the semaphore in the finally block so exceptions don't block other threads forever.
@@ -265,12 +269,14 @@ private async Task<HttpResponseMessage> RetryPypiRequestAsync(Uri uri, PipDepend | |||
/// <returns> Returns the httpresponsemessage. </returns> | |||
private async Task<HttpResponseMessage> GetPypiResponseAsync(Uri uri) | |||
{ | |||
await this.semaphore.WaitAsync(); |
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.
What kind of impact does this have on build times for small / large Python repositories? I see in the description only about 1 case.
This pr uses semaphore to reduce the amount of http requests to 5 concurrent requests at a time in both pip and simplepip. This is to avoid httpclient timing out due to too many requests at a time.
The fix also seems to have made the cd scan run faster. It was initially taking over 30 minutes to run on the vienna repo locally, but after throttling the requests the scan is taking about 23 minutes.
I also remove the manual disposal of httpclient, since its not recommended to manually dispose it.