-
Notifications
You must be signed in to change notification settings - Fork 21
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
fix: limit the max amount of concurrent network requests #116
Conversation
Without limiting the amount of concurrent network requests, installation fails with too many open files error
Benchmark ResultsLinux
|
crates/cli/src/commands/install.rs
Outdated
.unwrap(); | ||
self.install_dependencies(&dependency).await; | ||
.map(|(name, version)| { | ||
let semaphore_clone = semaphore.clone(); |
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 recommend Arc::clone(&semaphore)
to avoid confusing it with regular expensive .clone()
.
Is this related to the error on macOS? |
crates/cli/src/commands/install.rs
Outdated
@@ -55,17 +57,19 @@ impl PackageManager { | |||
package | |||
.dependencies(self.config.auto_install_peers) | |||
.map(|(name, version)| async { | |||
let semaphore_clone = semaphore.clone(); |
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.
semaphore
is not an Arc
here. Cloning it would create a new Semaphore
. Is this intentional?
This is one of the errors on macOS. The other one is Also, this PR is not ready yet. Looks like this change is causing a deadlock. |
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.
Can you add a test so that we don't regress in the future?
@@ -59,13 +60,15 @@ impl PackageManager { | |||
/// 5. Symlink all dependencies to node_modules/.pacquet/pkg@version/node_modules | |||
/// 6. Update package.json | |||
pub async fn add(&mut self, args: &AddCommandArgs) -> Result<(), PackageManagerError> { | |||
let semaphore = Arc::new(Semaphore::new(16)); |
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 think this should be configurable somehow
I don't get deadlock on my machine. What is your |
I am using this package.json |
This is a different one. I also get this one. pnpm solves this by using graceful-fs, which retries the file system operations on these type of errors. |
) -> Result<Self, RegistryError> { | ||
let url = || format!("{registry}{name}"); // TODO: use reqwest URL directly | ||
let network_error = |error| NetworkError { error, url: url() }; | ||
let _permit = semaphore.acquire().await; |
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.
Is there a reason you gave this value a name? If you want to postpone dropping it, I recommend explicitly calling drop
(i.e. drop(permit)
) at the end of the scope. If you only want to .await
the semaphore, please remove let _permit =
.
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.
won't it be dropped immediately if I don't assign it to a value? As far as I understand, the permit is dropped, when it goes out of scope.
After updating the You may try it with |
If I set the semaphore number to 1000, this error appears:
But if I don't, the install process never stops. |
I also created a more "polished" version here: df491ea Same result. |
I think the issue might be that pacquet doesn't support circular dependencies yet. |
It would helps a lot if you can reduce your |
As I have mentioned in #124, there are tests in pnpm related to circular dependencies. And there are small mock packages for testing: https://github.com/pnpm/registry-mock/tree/main/packages/circular-deps-1-of-2 |
Without limiting the amount of concurrent network requests, installation fails with too many open files error