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

Limit concurrent HTTP requests when downloading binary dependencies #4017

Merged
merged 4 commits into from
Jan 14, 2022
Merged

Limit concurrent HTTP requests when downloading binary dependencies #4017

merged 4 commits into from
Jan 14, 2022

Conversation

plu
Copy link
Contributor

@plu plu commented Jan 13, 2022

Limit the concurrent HTTP requests for downloading binary dependencies to 8 concurrent requests.

Motivation:

We have a fairly large Package.swift with 50 binary dependencies. In total the size of these 50 zip files is 400 MB. On a slower internet connection (16 MBit) the swift package resolve command errors out with some HTTP timeouts. It seems the main problem is that all 50 HTTP requests are executed at the same time.

Modifications:

Using some DispatchSemaphore to limit the concurrently downloaded binary dependencies to 8 concurrent requests.

Result:

In our project with the 50 binary dependencies it successfully completes the swift package resolve command. It's still open for discussion if the max 8 concurrent downloads is the right number. Also not sure if we should introduce another queue for this, reusing callbackQueue doesn't feel exactly right. However I found another TODO that's also just using callbackQueue and wondering if there should be a separate queue.

@plu
Copy link
Contributor Author

plu commented Jan 13, 2022

See also: https://bugs.swift.org/browse/SR-15725

@plu plu changed the title Limit concurrent download of binary dependencies Limit concurrent HTTP requests when downloading binary dependencies Jan 13, 2022
@plu
Copy link
Contributor Author

plu commented Jan 13, 2022

@swift-ci Please smoke test

// finally download zip files, if any
for artifact in (zipArtifacts.map{ $0 }) {
semaphore.wait()
Copy link
Contributor

@tomerd tomerd Jan 13, 2022

Choose a reason for hiding this comment

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

similar to how we handle group, we should should also defer a signal on the semaphore and then another wait after L2289, otherwise the continue from L2284 may create problems

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, maybe we should do group.enter() and semaphore.wait() only once after the guard, when we're sure we're actually executing the asynchronous HTTP request? Probably I'm just missing some detail about the lines before the guard though, not understanding the full picture why they also should be part of the DispatchGroup. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just pushed 97ccc8d - which is what I meant with my earlier comment. If this is wrong for some reason that I don't see yet, please let me know and I'll revert it and make the change you suggested in your first comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes this seems like a good change!

@tomerd
Copy link
Contributor

tomerd commented Jan 13, 2022

thanks @plu, couple of follow up questions

@tomerd tomerd self-assigned this Jan 13, 2022
@plu
Copy link
Contributor Author

plu commented Jan 13, 2022

Thank you for the quick review @tomerd. I made one change already, and had another question related to the code around the DispatchGroup.

@tomerd
Copy link
Contributor

tomerd commented Jan 13, 2022

@swift-ci please smoke test

@tomerd tomerd merged commit d41c85b into swiftlang:main Jan 14, 2022
@tomerd
Copy link
Contributor

tomerd commented Jan 14, 2022

@plu would you please also create a cherry-pick into the release/5.6 branch

@plu plu deleted the SR-15725 branch January 14, 2022 05:19
@plu
Copy link
Contributor Author

plu commented Jan 14, 2022

Thank you for the review/approval, @tomerd. Here's the PR that cherry-picks the commit into release/5.6: #4024

@plu
Copy link
Contributor Author

plu commented Jan 14, 2022

Is this something that Xcode is using directly, or should I file some radar for Xcode? I'm asking because we're also facing this issue when we do File -> Packages -> Resolve Package Versions in Xcode.

@tomerd
Copy link
Contributor

tomerd commented Jan 14, 2022

@plu this will be included in Xcode in the next release cycle

tomerd pushed a commit that referenced this pull request Jan 14, 2022
…4017) (#4024)

* Limit concurrent download of binary dependencies
* Add retryStrategy for downloading binary dependencies
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.

None yet

2 participants