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

Nixpkgs performance regression #3594

Closed
edolstra opened this issue Aug 14, 2014 · 49 comments
Closed

Nixpkgs performance regression #3594

edolstra opened this issue Aug 14, 2014 · 49 comments

Comments

@edolstra
Copy link
Member

Doing nix-env -qa on master now takes 2.81s on my system, while on the 14.04 branch it was only 1.72s, a 63% increase. Meanwhile the number of packages only increased by 9%.

We should do a bisect to figure out what caused the slowdown.

@edolstra edolstra added this to the 14.10 milestone Aug 14, 2014
@madjar
Copy link
Member

madjar commented Oct 6, 2014

@edolstra I wrote a small script to graph the evolution of the evaluation time, but I discovered it was constant. I tried on another computer (one with a SSD), and I have found a difference between master and 14.04.

Can you confirm that you have a SSD and that the evaluation is IO-bound otherwise?

Anyway, I'll use my script on my SSD-computer and show you the results.

@edolstra
Copy link
Member Author

edolstra commented Mar 4, 2015

Another big regression: nix-env -qa on the 14.12 branch takes 1.89s on my system, but 3.03s on master. More than 50% increase.

With nix-env -qa --out-path, it's even worse: up from 13.4s to 34.0s, and max resident size going 861 MB to 1933 MB.

A quick git bisect points at 62bfe75, but there may be other contributors.

@edolstra
Copy link
Member Author

edolstra commented Mar 4, 2015

This may be related to the OOMs while evaluating the nixos:trunk-combined jobset.

@edolstra
Copy link
Member Author

edolstra commented Mar 5, 2015

The OOMs may have started here: b2fdcf8

@offlinehacker
Copy link
Contributor

Yes, it could be because of nodePackages.
On Mar 5, 2015 11:03 AM, "Eelco Dolstra" notifications@github.com wrote:

The OOMs may have started here: b2fdcf8
b2fdcf8


Reply to this email directly or view it on GitHub
#3594 (comment).

@offlinehacker
Copy link
Contributor

I actually tought that this could happen after i automatically detect platforms on which node packages should be built. The fact is these few exported node packages have a lot of dependencies and recursive dependency avoidance algorithm is not so trivial. So if anyone could propose optimization or we don't export those packages.

@offlinehacker
Copy link
Contributor

I will try to optimizem it for sake of evaluation in following days.

@domenkozar
Copy link
Member

@offlinehacker can we revert meanwhile?

@offlinehacker
Copy link
Contributor

Meh, i will comment out platforms, don't revert or it will break node
packages probably.
On Mar 7, 2015 7:28 PM, "Domen Kožar" notifications@github.com wrote:

@offlinehacker https://github.com/offlinehacker can we revert meanwhile?


Reply to this email directly or view it on GitHub
#3594 (comment).

@vcunat
Copy link
Member

vcunat commented Mar 7, 2015

I think meta.platform changes should have no practical impact on performance of evaluation (for nix-env -qa).

@lucabrunox
Copy link
Contributor

Reverting b2fdcf8 doesn't solve the problem for me.

@lucabrunox
Copy link
Contributor

Forget about the above comment, I'm able to nix-instantiate nixos/release-combined.nix -A tested of commit ed75d61 (6 hours ago). It took about 2 minutes and 6.5gb of ram.
Also a commit of like 10 weeks ago requires about the same amount of time and ram, maybe slightly less time.

Perhaps I should try evaluating the whole release-combined instead of only "tested", not sure I will be able to do it with my ram :(

@lucabrunox
Copy link
Contributor

I'm also able to evaluate the whole nix-instantiate nixos/release-combined.nix

@domenkozar
Copy link
Member

@edolstra could you help out with the hydra issue? I have to revert back to 14.12 because VirtualBox update is not in the current master channel

@domenkozar
Copy link
Member

I can evaluate master with reverting b2fdcf8, without that it gets killed by OOM (8GB of ram).

@offlinehacker I'm reverting the commit if you don't find a reasonable argument/solution in a day. We haven't updated unstable channel in 17 days and nixpkgs in 40 days. This is slowing down development of NixOS project quite a bit.

@offlinehacker
Copy link
Contributor

Ok, i will take time tomorrow(today to be more precise) to fix this, if i
don't figure it out, i will revert it in a way that it will not break all
nodePackages.
On Mar 15, 2015 9:04 PM, "Domen Kožar" notifications@github.com wrote:

I can evaluate master with reverting b2fdcf8
b2fdcf8,
without that it gets killed by OOM (8GB of ram).

@offlinehacker https://github.com/offlinehacker I'm reverting the
commit if you don't find a reasonable argument/solution in a day. We
haven't updated unstable channel in 17 days and nixpkgs in 40 days. This is
slowing down development of NixOS project quite a bit.


Reply to this email directly or view it on GitHub
#3594 (comment).

@domenkozar
Copy link
Member

Hmmm, I can also evaluate master with 6.5GB of ram. @edolstra is it because hydra uses old kernel? I'm using 3.18.

@domenkozar
Copy link
Member

I've pushed 1e4ba02.

PS: /nix/store/kdfywafkcyhnws66i06va6vn83xihzmi-hydra-0.1pre1234-abcdef/bin/hydra-eval-jobs /home/ielectric/dev/nixpkgs/nixos/release-combined.nix >/dev/null gets killed by OOM on my 8GB of ram.

@offlinehacker
Copy link
Contributor

How can i test performance issues, i was trying to fix this today, i don't have 8GB of ram to try to evaluate everything. If i do nix-env -f default.nix -i nodejs-bower-1.3.12 i don't get any GC errors. I would like someone to help me debug the problem, not just revert some commits and then break a lot of packages. I will try to debug this tomorrow on 32G server, i have to install nix there first.

@lucabrunox
Copy link
Contributor

Will try with hydra-eval-jobs instead of nix-build.

@peti
Copy link
Member

peti commented Mar 18, 2015

@offlinehacker, in all fairness, it's not like someone "just revert some commits".

Also, note that @iElectric has posted the exact command-line he's using to re-produce the problem.

@lucabrunox
Copy link
Contributor

So with a commit of 6 days ago 0bc51ea (because of binary cache) I can reproduce the problem with hydra-eval-jobs. But I don't think it's something related to node packages, honestly. Node packages were evaluated just fine. The fact that's the commit where hydra stopped evaluating, is not a 1:1 indication it's a node packages problem. @iElectric you wasn't very clear, were you able to evaluate the jobset after reverting the commits, while you weren't before?

Here it stopped when evaluating tests, right after the i3wm test. The problem is just it needs more ram nowadays, I believe. Nothing related to node packages. E.g. the evaluation hit 7.9gb of ram out of 8gb for a long time, so the GC was a lot aggressive on keeping below the max ram. At some point however it just needed more ram, wasn't there, and stopped. That's it, at least what I observed.

@domenkozar
Copy link
Member

There we go, first eval after a month: http://hydra.nixos.org/eval/1178620

@domenkozar
Copy link
Member

@offlinehacker with 0461f35 you could try applying nodePackages fixes again and see how much it increases memory usage

@offlinehacker
Copy link
Contributor

@iElectric nice, so with current master i get 4.45s for nix-env -f default.nix -qa and the same value on origin/master, so i guess that's and i can succesfully evaluate nix-instantiate nixos/release-combined.nix on my laptop with 4G ram and if i compare with origin/master it is almost same memory usage. I'm reverting your reverts now. If there's something i'm missing, please let me know.

@domenkozar
Copy link
Member

With nodePackages problematic commits (master):

Memory usage: 5149MB (105% increase)
Time to evaluate: 244s (16% increase)

Without the problematic commits (51d4656):

Memory usage: 2508MB
Time to evalute: 209s

PS: tested with

`which time` -f "%P %M" /nix/store/kdfywafkcyhnws66i06va6vn83xihzmi-hydra-0.1pre1234-abcdef/bin/hydra-eval-jobs /home/ielectric/dev/nixpkgs/nixos/release-combined.nix >/dev/null

@domenkozar
Copy link
Member

@edolstra do you think the regression is bad enough not to have such commits?

@offlinehacker
Copy link
Contributor

Well the real problem is that i don't have any idea what's going on in hydra-eval-jobs that's causing such memory usage, what can i easily make is disable building node packages on hydra.

@domenkozar
Copy link
Member

That might be a good solution as build time is very quick for npm/iojs

@offlinehacker
Copy link
Contributor

Not so quick anymore in comparisson how fast npm is now.

@offlinehacker
Copy link
Contributor

Ok, is there any better way to disable builds on hydra as removing platforms?

@domenkozar
Copy link
Member

By removing recurseIntoAttrs at https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix#L1791 (and the same for iojsPackages)

@offlinehacker
Copy link
Contributor

Ah, ok 👍

@domenkozar
Copy link
Member

2273MB 👍

@vcunat
Copy link
Member

vcunat commented Jun 9, 2015

So I looked into this, and bisecting was fast enough (about 12 steps between master and the merge-base against 14.12): 8fb5494 add kde-applications-14.12.1.

On my notebook there's a distinct jump on that single commit – all I've seen before was faster and all after was slower than the point of jump (from the ~11 commits tried in-between).

$ git co 8fb5494309d
$ NIX_PATH= time nix-env -f . -qa > /dev/null
9.10user 0.42system 0:09.54elapsed 99%CPU (0avgtext+0avgdata 569920maxresident)k
0inputs+0outputs (0major+143823minor)pagefaults 0swaps

$ git co HEAD^
$ NIX_PATH= time nix-env -f . -qa > /dev/null
4.41user 0.37system 0:04.79elapsed 99%CPU (0avgtext+0avgdata 567820maxresident)k
0inputs+0outputs (0major+143340minor)pagefaults 0swaps

ATM I don't see what makes it so slow, /cc @ttuegel. Just removing recurseIntoAttrs for kde doesn't help noticeably for me (though it removes quite a few packages).

@ttuegel
Copy link
Member

ttuegel commented Jun 9, 2015

@vcunat It's probably because that commit adds ~2.8k lines of Nix code between two files. Are you sure you removed recurseIntoAttrs for kdeApps_14_12?

@vcunat
Copy link
Member

vcunat commented Jun 9, 2015

Yes, sure (I did check that KDE packages disappeared from the list). A better test case is:

command time nix-instantiate -A kde4.kdelibs

... counting second and further runs, as the first one can create derivations. For me it jumps from ~0.26s to ~3.9s!

@ttuegel
Copy link
Member

ttuegel commented Jun 9, 2015

That makes sense. kde4 now gets its kdelibs from kdeApps_stable because that is where the KDE team releases updates. So, evaluating kde4.kdelibs requires first parsing all of kdeApps_stable (note: parsing, not evaluating). I think the best way forward here is to split up the expressions into individual files for optimum laziness, and we probably need to do the same for the other large package collections.

@vcunat
Copy link
Member

vcunat commented Jun 9, 2015

Would you look at it? (To avoid duplicating effort; though I'd be unlikely to do it today anyway.)

@ttuegel
Copy link
Member

ttuegel commented Jun 9, 2015

Sure, I'll take a look.

One remark I can make off-hand is that something is different about the KDE packages because evaluating a package from haskellPackages (which is a much larger collection) takes only a fraction of a second on my system.

@vcunat
Copy link
Member

vcunat commented Jun 9, 2015

I'd expect some of the many transformations in there is/are expensive, as the kde expressions are built in a rather complex way.

@vcunat
Copy link
Member

vcunat commented Jun 25, 2015

Sounds great! Thanks a lot :-)

@domenkozar
Copy link
Member

We're back to 7.5G of memory usage for nixos/release-combined.nix

@domenkozar
Copy link
Member

I removed recurseIntoAttrs for node 5.0 and 4.3 packages and it's now down to 4.6G.

domenkozar added a commit that referenced this issue Dec 28, 2015
Two reasons for this change:

- most of 5.0 packages don't build yet

- node packages are memory intensive and block Hydra evaluation
  (Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS)

PS: Removing node packages from evaluation goes from 7.5G down to
4.6G for whole nixos release job.

See #3594 and #11865
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants