Skip to content

pkgs/top-level/release-outpaths-parallel.nix 5x faster eval checks#269403

Closed
ghost wants to merge 26 commits intomasterfrom
unknown repository
Closed

pkgs/top-level/release-outpaths-parallel.nix 5x faster eval checks#269403
ghost wants to merge 26 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Nov 23, 2023

This PR is implemented entirely in pure Nix code and a single call to xargs.

  • It has already been used to build the entire release packageset at larger-than-Hydra scale.
    • This is a complete, working solution, not a component or a theoretical possibility.
  • It works with any Nix interpreter, and is not cppnix-specific like Hydra is.
    • It does not need to link against any cppnix shared libraries.
    • It does not use cppnix's internal interfaces.
  • It is in-tree as part of nixpkgs
    • It does not add additional out-of-repo dependencies with their own gatekeeping committees.

Results

On a 32-core machine, the following command takes 4m58s:

NIX_BUILD_CORES=32 time pkgs/top-level/release-outpaths-parallel.sh false

and produces exactly the same output as this command (the one ofborg uses), which takes 24m10s:

time nix-env -qaP --no-name --out-path --arg checkMeta false -f pkgs/top-level/release-outpaths.nix | sort

... in 1/5th of the wall-clock time. So the eval-check latency is reduced by 5x. With checkMeta=true the ratio is almost identical: 37m54s with the current method, 7m38s with release-outpaths-parallel.

There is room to improve even further:

  • Half of the 4m58s is spent in the (completely serial) release-attrpaths-superset.nix process. However that process produces output incrementally, meaning that the parallel part of the eval-checks can be started as soon as the first line of release-attrpaths-superset.nix output is produced -- this should give another 25% improvement.
  • Right now the 4*NUM_CORES chunks are scheduled blindly, by simply taking alphabetical chunks of job attrpaths. This results in a huge amount of duplicated work. Simple dependency-based scheduling (possibly using the previous commit's attrpath dependency graph as an approximation of the current one) should give another large boost, possibly even 50%.

Includes

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: haskell General-purpose, statically typed, purely functional programming language 6.topic: qt/kde Object-oriented framework for GUI creation 6.topic: emacs Text editor 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 6.topic: erlang General-purpose, concurrent, functional high-level programming language 6.topic: steam Steam game store/launcher (store.steampowered.com) 6.topic: lua Lua is a powerful, efficient, lightweight, embeddable scripting language. 6.topic: module system About "NixOS" module system internals 6.topic: lib The Nixpkgs function library labels Nov 23, 2023
@ghost ghost changed the title pkgs/top-level/release-outpaths-parallel.{nix,sh}: init 5x faster eval checks pkgs/top-level/release-outpaths-parallel.{nix,sh}: 5x faster eval checks Nov 23, 2023
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try nix-eval-jobs, it does parallel but doesn't help with memory usage AFAIK

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It helps with memory usage as well because it restarts workers if they take too much memory. The chunking at the moment might be less ideal because it doesn't chunk the list into X parts and gives this to threads but instead starts to iterate the list from the beginning and give each thread an attribute in lexical key order. I think it would be faster if attributes closer to each other would be evaluated by the same thread to avoid evaluating the same thing twice (i.e. x86_64-linux packages evaluated on thread1 and aarch64-linux packages on thread2).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However from my tests I would say that having more threads than CPUs will actually slow you down because you end up evaluating the same thing more. I usually have less threads than cores for large package sets like nixpkgs to avoid duplicating work and rather trait it for memory.

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Nov 23, 2023
@NixOS NixOS locked and limited conversation to collaborators Nov 27, 2023
@NixOS NixOS unlocked this conversation Nov 27, 2023
@cole-h
Copy link
Member

cole-h commented Nov 27, 2023

(Sorry, GitHub mobile fat finger...... Love how there's no confirmation...)

@adisbladis
Copy link
Member

I would like to note that using this in ofborg would mean giving up the performance report, at least as it is today.

@adisbladis
Copy link
Member

Conceptually this PR works similarly to how nix-eval-jobs works, just implemented as a pile of shell/nix instead of using the evaluator directly.
I think it's better to make ofborg use nix-eval-jobs.

cc NixOS/ofborg#440

@github-actions github-actions bot removed 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: steam Steam game store/launcher (store.steampowered.com) labels Nov 30, 2023
infinisil added a commit to tweag/nixpkgs that referenced this pull request Nov 14, 2024
@nixos-discourse
Copy link

@nixos-discourse
Copy link

Bot-wxt1221 pushed a commit to Bot-wxt1221/nixpkgs that referenced this pull request Nov 19, 2024
Motivated by ofborg struggling [1] and its evaluations taking too long,
inspired by Jörg's initial PR [2]
and Adam's previous attempt to parallelise Nixpkgs evaluation [3],
this PR contains initial work to relief ofborg from its evaluation duty
by using GitHub Actions to evaluate Nixpkgs.

For now this doesn't take care of all of what ofborg does, such as
requesting appropriate reviewers or labeling mass rebuilds, but this can
be follow-up work.

[1]: https://discourse.nixos.org/t/infrastructure-announcement-the-future-of-ofborg-your-help-needed/56025?u=infinisil
[2]: NixOS#352808
[3]: NixOS#269403

Co-Authored-By: Jörg Thalheim <[email protected]>
Co-Authored-By: Adam Joseph <[email protected]>
Bot-wxt1221 added a commit to Bot-wxt1221/nixpkgs that referenced this pull request Nov 19, 2024
* [WIP] Parallel GH actions workflow for Nixpkgs eval

Partly taken from NixOS#352808 and NixOS#269403

* ci/parallel.nix: nixfmt

* ci/eval: drop swap

Turns out we don't actually need it

* ci/eval: reformat with shfmt

the file was using mixed indentation (2 vs 4 spaces)

* ci/eval: depend on coreutils

nproc is only part of coreutils and not present on macOS

* ci/eval: allow to override cores

this is useful to control how much RAM is used during evaluation

* ci/eval: use xargs instead of parallel

saves us from having to install perl for this script.

* ci/eval: add quick test flag

* ci/eval: seperate different outputs in json

* WIP

* Update README.md

---------

Co-authored-by: Silvan Mosberger <[email protected]>
Co-authored-by: Jörg Thalheim <[email protected]>
Co-authored-by: Silvan Mosberger <[email protected]>
infinisil added a commit to tweag/nixpkgs that referenced this pull request Nov 20, 2024
Motivated by ofborg struggling [1] and its evaluations taking too long,
inspired by Jörg's initial PR [2]
and Adam's previous attempt to parallelise Nixpkgs evaluation [3],
this PR contains initial work to relief ofborg from its evaluation duty
by using GitHub Actions to evaluate Nixpkgs.

For now this doesn't take care of all of what ofborg does, such as
requesting appropriate reviewers or labeling mass rebuilds, but this can
be follow-up work.

[1]: https://discourse.nixos.org/t/infrastructure-announcement-the-future-of-ofborg-your-help-needed/56025?u=infinisil
[2]: NixOS#352808
[3]: NixOS#269403

Co-Authored-By: Jörg Thalheim <[email protected]>
Co-Authored-By: Adam Joseph <[email protected]>
infinisil added a commit to tweag/nixpkgs that referenced this pull request Nov 20, 2024
Motivated by ofborg struggling [1] and its evaluations taking too long,
inspired by Jörg's initial PR [2]
and Adam's previous attempt to parallelise Nixpkgs evaluation [3],
this PR contains initial work to relief ofborg from its evaluation duty
by using GitHub Actions to evaluate Nixpkgs.

For now this doesn't take care of all of what ofborg does, such as
requesting appropriate reviewers or labeling mass rebuilds, but this can
be follow-up work.

[1]: https://discourse.nixos.org/t/infrastructure-announcement-the-future-of-ofborg-your-help-needed/56025?u=infinisil
[2]: NixOS#352808
[3]: NixOS#269403

Co-Authored-By: Jörg Thalheim <[email protected]>
Co-Authored-By: Adam Joseph <[email protected]>
github-actions bot pushed a commit that referenced this pull request Nov 20, 2024
Motivated by ofborg struggling [1] and its evaluations taking too long,
inspired by Jörg's initial PR [2]
and Adam's previous attempt to parallelise Nixpkgs evaluation [3],
this PR contains initial work to relief ofborg from its evaluation duty
by using GitHub Actions to evaluate Nixpkgs.

For now this doesn't take care of all of what ofborg does, such as
requesting appropriate reviewers or labeling mass rebuilds, but this can
be follow-up work.

[1]: https://discourse.nixos.org/t/infrastructure-announcement-the-future-of-ofborg-your-help-needed/56025?u=infinisil
[2]: #352808
[3]: #269403

Co-Authored-By: Jörg Thalheim <[email protected]>
Co-Authored-By: Adam Joseph <[email protected]>
(cherry picked from commit fbbe972)
Mic92 added a commit to Mic92/nixpkgs that referenced this pull request Nov 21, 2024
Motivated by ofborg struggling [1] and its evaluations taking too long,
inspired by Jörg's initial PR [2]
and Adam's previous attempt to parallelise Nixpkgs evaluation [3],
this PR contains initial work to relief ofborg from its evaluation duty
by using GitHub Actions to evaluate Nixpkgs.

For now this doesn't take care of all of what ofborg does, such as
requesting appropriate reviewers or labeling mass rebuilds, but this can
be follow-up work.

[1]: https://discourse.nixos.org/t/infrastructure-announcement-the-future-of-ofborg-your-help-needed/56025?u=infinisil
[2]: NixOS#352808
[3]: NixOS#269403

Co-Authored-By: Jörg Thalheim <[email protected]>
Co-Authored-By: Adam Joseph <[email protected]>
github-actions bot pushed a commit to nix-community/nixpkgs.lib that referenced this pull request Nov 24, 2024
Motivated by ofborg struggling [1] and its evaluations taking too long,
inspired by Jörg's initial PR [2]
and Adam's previous attempt to parallelise Nixpkgs evaluation [3],
this PR contains initial work to relief ofborg from its evaluation duty
by using GitHub Actions to evaluate Nixpkgs.

For now this doesn't take care of all of what ofborg does, such as
requesting appropriate reviewers or labeling mass rebuilds, but this can
be follow-up work.

[1]: https://discourse.nixos.org/t/infrastructure-announcement-the-future-of-ofborg-your-help-needed/56025?u=infinisil
[2]: NixOS/nixpkgs#352808
[3]: NixOS/nixpkgs#269403

Co-Authored-By: Jörg Thalheim <[email protected]>
Co-Authored-By: Adam Joseph <[email protected]>
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: emacs Text editor 6.topic: erlang General-purpose, concurrent, functional high-level programming language 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: haskell General-purpose, statically typed, purely functional programming language 6.topic: lib The Nixpkgs function library 6.topic: lua Lua is a powerful, efficient, lightweight, embeddable scripting language. 6.topic: module system About "NixOS" module system internals 6.topic: qt/kde Object-oriented framework for GUI creation 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants