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

feat: make concurrency more configurable #2388

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions crates/pixi_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub enum DetachedEnvironments {
Boolean(bool),
Path(PathBuf),
}

impl DetachedEnvironments {
pub fn is_false(&self) -> bool {
matches!(self, DetachedEnvironments::Boolean(false))
Expand Down Expand Up @@ -260,6 +261,7 @@ pub enum PinningStrategy {
// Calling it no-pin to make it simple to type, as other option was pin-unconstrained.
NoPin,
}

impl FromStr for PinningStrategy {
type Err = serde::de::value::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand Down Expand Up @@ -348,6 +350,22 @@ impl PinningStrategy {
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct Concurrency {
/// The maximum number of concurrent HTTP requests to make.
#[serde(default)]
pub network_requests: usize,
}

impl Default for Concurrency {
fn default() -> Self {
Self {
network_requests: 50,
}
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct Config {
Expand Down Expand Up @@ -409,6 +427,9 @@ pub struct Config {
/// it back to the .pixi folder.
#[serde(skip_serializing_if = "Option::is_none")]
pub detached_environments: Option<DetachedEnvironments>,

/// Concurrency settings.
pub concurrency: Option<Concurrency>,
}

impl Default for Config {
Expand All @@ -425,6 +446,7 @@ impl Default for Config {
pypi_config: PyPIConfig::default(),
detached_environments: Some(DetachedEnvironments::default()),
pinning_strategy: Default::default(),
concurrency: None,
}
}
}
Expand Down Expand Up @@ -688,6 +710,7 @@ impl Config {
pypi_config: other.pypi_config.merge(self.pypi_config),
detached_environments: other.detached_environments.or(self.detached_environments),
pinning_strategy: other.pinning_strategy.or(self.pinning_strategy),
concurrency: other.concurrency.or(self.concurrency),
}
}

Expand Down Expand Up @@ -745,6 +768,10 @@ impl Config {
self.detached_environments.clone().unwrap_or_default()
}

pub fn concurrency(&self) -> Concurrency {
self.concurrency.clone().unwrap_or_default()
}

/// Modify this config with the given key and value
///
/// # Note
Expand Down
4 changes: 3 additions & 1 deletion src/global/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,12 +1020,14 @@
}

impl Repodata for Project {
/// Returns the [`Gateway`] used by this project.

Check warning on line 1023 in src/global/project/mod.rs

View workflow job for this annotation

GitHub Actions / Cargo Format

Diff in /home/runner/work/pixi/pixi/src/global/project/mod.rs
fn repodata_gateway(&self) -> &Gateway {
self.repodata_gateway.get_or_init(|| {
tracing::info!("Concurrency is set to: {}", self.config().concurrency().network_requests);
Self::repodata_gateway_init(
self.authenticated_client().clone(),
self.config().clone().into(),
self.config().into(),
self.config().concurrency().network_requests,
)
})
}
Expand Down
3 changes: 2 additions & 1 deletion src/project/repodata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ impl Repodata for Project {
self.repodata_gateway.get_or_init(|| {
Self::repodata_gateway_init(
self.authenticated_client().clone(),
self.config().clone().into(),
self.config().into(),
self.config().concurrency().network_requests,
)
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/repodata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub(crate) trait Repodata {
fn repodata_gateway_init(
authenticated_client: reqwest_middleware::ClientWithMiddleware,
channel_config: ChannelConfig,
max_concurrent_requests: usize,
) -> Gateway {
// Determine the cache directory and fall back to sane defaults otherwise.
let cache_dir = pixi_config::get_cache_dir().unwrap_or_else(|e| {
Expand All @@ -22,6 +23,7 @@ pub(crate) trait Repodata {
.with_cache_dir(cache_dir.join(pixi_consts::consts::CONDA_REPODATA_CACHE_DIR))
.with_package_cache(package_cache)
.with_channel_config(channel_config)
.with_max_concurrent_requests(max_concurrent_requests)
.finish()
}

Expand Down
Loading