diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2025-05-30 17:17:52 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2025-05-30 17:43:25 +0200 |
commit | f4e9de93b50fe8135d378830577cda687cae28ee (patch) | |
tree | e14f306aba4fb9c6b83c8ee9990204eece9d17ac /src/buildtool/main/build_utils.cpp | |
parent | 39f0445a99cbb1256c531f8ec827aea424e328c3 (diff) | |
download | justbuild-f4e9de93b50fe8135d378830577cda687cae28ee.tar.gz |
WriteTargetCacheEntries: do not use quadratic many jobs
When backing up target-cache entries we use parallelism at two
dimensions, the independent cache entries and for each entry we
retrieve the artifacts in parallel. If for each dimension we use
the full amount of parallelism allowed, that gives a number of
threads up to the square of the amount of parallelism specified by
the user. Therefore, use in each dimension only the square root
of the allowed parallelism keeping the total parallelism (up to
rounding) within the specified range.
Diffstat (limited to 'src/buildtool/main/build_utils.cpp')
-rw-r--r-- | src/buildtool/main/build_utils.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/buildtool/main/build_utils.cpp b/src/buildtool/main/build_utils.cpp index 3b919ade..684d2dd1 100644 --- a/src/buildtool/main/build_utils.cpp +++ b/src/buildtool/main/build_utils.cpp @@ -14,6 +14,7 @@ #include "src/buildtool/main/build_utils.hpp" +#include <cmath> #include <iterator> #include <memory> #include <unordered_set> @@ -160,6 +161,7 @@ void WriteTargetCacheEntries( TargetCache<true> const& tc, Logger const* logger, LogLevel log_level) { + std::size_t sqrt_jobs = std::lround(std::ceil(std::sqrt(jobs))); if (strategy == TargetCacheWriteStrategy::Disable) { return; } @@ -171,7 +173,7 @@ void WriteTargetCacheEntries( } // set up writer map auto tc_writer_map = CreateTargetCacheWriterMap( - cache_targets, extra_infos, jobs, &apis, strategy, tc); + cache_targets, extra_infos, sqrt_jobs, &apis, strategy, tc); std::vector<Artifact::ObjectInfo> cache_targets_ids; cache_targets_ids.reserve(cache_targets.size()); for (auto const& [k, _] : cache_targets) { @@ -180,7 +182,7 @@ void WriteTargetCacheEntries( // write the target cache keys bool failed{false}; { - TaskSystem ts{jobs}; + TaskSystem ts{sqrt_jobs}; tc_writer_map.ConsumeAfterKeysReady( &ts, cache_targets_ids, |