Make max download threads configurable (#1377)

This commit is contained in:
Adrien Delsalle 2022-01-14 14:47:49 +01:00 committed by GitHub
parent 5ea020bbf5
commit d4acbf7dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 6 deletions

View File

@ -130,7 +130,9 @@ namespace mamba
ChannelPriority channel_priority = ChannelPriority::kFlexible;
bool auto_activate_base = false;
long max_parallel_downloads = 5;
std::size_t download_threads = 5;
int extract_threads = 0;
int verbosity = 0;
void set_verbosity(int lvl);
void set_log_level(const spdlog::level::level_enum& level);
@ -150,8 +152,6 @@ namespace mamba
bool always_copy = false;
bool always_softlink = false;
int extract_threads = 0;
// add start menu shortcuts on Windows (not implemented on Linux / macOS)
bool shortcuts = true;

View File

@ -460,6 +460,13 @@ namespace mamba
}
}
void download_threads_hook(std::size_t& value)
{
if (!value)
throw std::runtime_error(fmt::format(
"Number of download threads as to be positive (currently set to {})", value));
}
void extract_threads_hook()
{
DownloadExtractSemaphore::set_max(Context::instance().extract_threads);
@ -784,6 +791,16 @@ namespace mamba
.description("If solve fails, try to fetch updated repodata"));
// Extract, Link & Install
insert(Configurable("download_threads", &ctx.download_threads)
.group("Extract, Link & Install")
.set_rc_configurable()
.set_env_var_names()
.set_post_merge_hook(detail::download_threads_hook)
.description("Defines the number of threads for package download")
.long_description(unindent(R"(
Defines the number of threads for package download.
It has to be strictly positive.)")));
insert(Configurable("extract_threads", &ctx.extract_threads)
.group("Extract, Link & Install")
.set_rc_configurable()

View File

@ -159,7 +159,7 @@ namespace mamba
PRINT_CTX(use_only_tar_bz2)
PRINT_CTX(auto_activate_base)
PRINT_CTX(extra_safety_checks)
PRINT_CTX(max_parallel_downloads)
PRINT_CTX(download_threads)
PRINT_CTX(verbosity)
PRINT_CTX(channel_alias)
<< "channel_priority: " << (int) channel_priority << "\n"

View File

@ -557,7 +557,7 @@ namespace mamba
{
m_handle = curl_multi_init();
curl_multi_setopt(
m_handle, CURLMOPT_MAX_TOTAL_CONNECTIONS, Context::instance().max_parallel_downloads);
m_handle, CURLMOPT_MAX_TOTAL_CONNECTIONS, Context::instance().download_threads);
}
MultiDownloadTarget::~MultiDownloadTarget()

View File

@ -236,7 +236,7 @@ PYBIND11_MODULE(bindings, m)
.def_readwrite("offline", &Context::offline)
.def_readwrite("local_repodata_ttl", &Context::local_repodata_ttl)
.def_readwrite("use_index_cache", &Context::use_index_cache)
.def_readwrite("max_parallel_downloads", &Context::max_parallel_downloads)
.def_readwrite("download_threads", &Context::download_threads)
.def_readwrite("extract_threads", &Context::extract_threads)
.def_readwrite("always_yes", &Context::always_yes)
.def_readwrite("dry_run", &Context::dry_run)