Skip to content

Commit

Permalink
libstore: change max-jobs default to auto
Browse files Browse the repository at this point in the history
  • Loading branch information
Enzime committed Sep 25, 2023
1 parent 1e99b7a commit 024f4b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Release X.Y (202?-??-??)

- The `max-jobs` setting now defaults to `auto`.
8 changes: 6 additions & 2 deletions src/libstore/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,19 @@ std::vector<Path> getUserConfigFiles()
return files;
}

unsigned int Settings::getDefaultThreads()
{
return std::max(1U, std::thread::hardware_concurrency());
}

unsigned int Settings::getDefaultCores()
{
const unsigned int concurrency = std::max(1U, std::thread::hardware_concurrency());
const unsigned int maxCPU = getMaxCPU();

if (maxCPU > 0)
return maxCPU;
else
return concurrency;
return getDefaultThreads();
}

StringSet Settings::getDefaultSystemFeatures()
Expand Down
15 changes: 8 additions & 7 deletions src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const uint32_t maxIdsPerBuild =

class Settings : public Config {

unsigned int getDefaultThreads();

unsigned int getDefaultCores();

StringSet getDefaultSystemFeatures();
Expand Down Expand Up @@ -147,15 +149,14 @@ public:
"the log to show if a build fails."};

MaxBuildJobsSetting maxBuildJobs{
this, 1, "max-jobs",
this, getDefaultThreads(), "max-jobs",
R"(
This option defines the maximum number of jobs that Nix will try to
build in parallel. The default is `1`. The special value `auto`
causes Nix to use the number of CPUs in your system. `0` is useful
when using remote builders to prevent any local builds (except for
`preferLocalBuild` derivation attribute which executes locally
regardless). It can be overridden using the `--max-jobs` (`-j`)
command line switch.
build in parallel. The default is `auto` which causes Nix to use
the number of CPUs in your system. `0` is useful when using remote
builders to prevent any local builds (except for `preferLocalBuild`
derivation attribute which executes locally regardless). It can be
overridden using the `--max-jobs` (`-j`) command line switch.
)",
{"build-max-jobs"}};

Expand Down

0 comments on commit 024f4b6

Please sign in to comment.