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

Users/oakeredolu/throttlehttpclient #872

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Omotola
Copy link
Contributor

@Omotola Omotola commented Oct 20, 2023

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.

@Omotola Omotola requested a review from a team as a code owner October 20, 2023 23:00
@github-actions
Copy link

👋 Hi! It looks like you modified some files in the Detectors folder.
You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

Merging #872 (06c8504) into main (62c482b) will decrease coverage by 2.8%.
The diff coverage is 75.0%.

@@           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     
Files Coverage Δ
...ft.ComponentDetection.Detectors/pip/IPyPiClient.cs 59.6% <75.0%> (-4.5%) ⬇️
...mponentDetection.Detectors/pip/SimplePypiClient.cs 86.2% <75.0%> (-3.6%) ⬇️

... and 69 files with indirect coverage changes

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();
Copy link
Contributor

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();
Copy link
Contributor

@cobya cobya Nov 29, 2023

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.

@cobya cobya added status:waiting-on-response Waiting on a response/more information from the user type:refactor Refactoring or improving of existing code detector:pip The pip detector labels Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
detector:pip The pip detector status:waiting-on-response Waiting on a response/more information from the user type:refactor Refactoring or improving of existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants