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

ng serve uses a lot of CPU % #2748

Closed
areijngoudt opened this issue Oct 17, 2016 · 29 comments
Closed

ng serve uses a lot of CPU % #2748

areijngoudt opened this issue Oct 17, 2016 · 29 comments
Labels
needs: investigation Requires some digging to determine if action is needed

Comments

@areijngoudt
Copy link

Mac OSX El Capitan

Versions.

angular-cli: 1.0.0-beta.17
node: 5.7.1
os: darwin x64

angular-cli uses about 85% CPU when I only use ng serve during development, also when I'n not changing code but just use the webapp in a browser.

@kylecordes
Copy link

I experienced the same thing here. Sitting idle, with nothing changing, approximately one CPU core burns 100% in ng serve. Latest node, latest OSX, CLI beta 17.

@mseemann
Copy link

npm i fsevents should solve this.

@filipesilva filipesilva added command: serve needs: investigation Requires some digging to determine if action is needed labels Oct 17, 2016
@masaanli
Copy link

Not working on Windows.

@areijngoudt
Copy link
Author

installing fsevents solves this issue on mac. Thanks @mseemann

@rryter
Copy link
Contributor

rryter commented Oct 31, 2016

I don't think this issue should be closed. Manually installing fsevents can not be the longterm solution.

@benyaminshoham
Copy link

Does it make sense to add fsevents to the dependencies of @angular/cli?

@msnatu
Copy link

msnatu commented Apr 4, 2017

@mseemann Thanks a lot!

@jlberrocal
Copy link

fsevents only work for mac, but what about windows and linux, in my case what is literally eating is my ram, ng process consumes 1.2GB which i consider a lot for a process like that one

@JohannesRudolph
Copy link
Contributor

JohannesRudolph commented Jun 7, 2017 via email

@Almenon
Copy link

Almenon commented Sep 22, 2017

have you tried using task manager to lower the affinity / priority of the process?

@chestercharles
Copy link

chestercharles commented Nov 15, 2017

@Almenon 's solution to lower the affinity/priority of the process has been working for me. However, it is kinda tedious to do every time I run ng serve.

If I don't manually lower the affinity/priority of the process, my CPU usage is at 99%.

Running on windows 8

@trumbitta
Copy link

@rryter also, if I add it to my package.json every build not happening under Mac OS will fail:

npm ERR! notsup Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

@trumbitta
Copy link

I ended up adding the following little script to my postinstall:

const isMac = /^darwin/.test(process.platform);

if (isMac === true) {
  const process = require('child_process');
  process.execSync('npm install fsevents --no-save');
}

@rightisleft
Copy link

rightisleft commented Dec 7, 2017

Running under debian, using the ng serve --poll command causes my cpu to spike to %300 (3coresx100)

@smallg
Copy link

smallg commented Mar 29, 2018

this is very useful

@azcdev
Copy link

azcdev commented May 12, 2018

Can somebody explain why fsevents solves this issue? Posting a solution without an explanation isn't helpful.

@sonjaerock
Copy link

What is solution on linux ?

@PyroSA
Copy link

PyroSA commented Jun 5, 2018

@alanchavez88 fsevents allows the process to subscribe to File System EVENTS.

I can only assume angular-cli has logic built in that makes use of this if it's available.

This means that angular-cli no longer has to poll the actual files to see if changes occurred, it simply waits for OSX to notify it of a file change.

EDIT: Just to confirm, fsevents calmed down my CPU as well. No more hand-warmer.

@electrichead
Copy link

electrichead commented Jun 9, 2018

@alanchavez88 further to @PyroSA reply: it might have to do with chokidar, which is used by karma and the @angular/compiler-cli for watching files for changes. Chokidar is a wrapper around different ways to watch for files and fsevents is one of those. Chokidar has fsevents as an optional dependency - if it's present it will use it otherwise it has fallbacks. So if nothing else installs fsevents, chokidar goes with one of the alternatives and that eats up CPU because of polling.

https://www.npmjs.com/package/chokidar#performance

You can add "fsevents" to "optionalDependencies" in package.json to persist this change.

@pattersongp
Copy link

For anyone running on Linux, I've been running my build and serve with a lower priority. It's really helped with ng hogging the CPU.

You can try:
$ nice -10 ng <build, search> --watch true or poll N which appears to do the trick.

This should also work on other *NIX OS's

@PyroSA
Copy link

PyroSA commented Jul 6, 2018

Increasing the polling interval is enough to calm down the watching and will work even on non *nix.

I helped our Windows guys with their overeager virus scanners in the past.

@tebantebanteban
Copy link

same issue here

Angular CLI: 6.1.1
Node: 10.7.0
OS: darwin x64
Angular: 6.1.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.7.1
@angular/cli                      6.1.1
@ngtools/webpack                  6.0.8
@schematics/angular               0.7.1
@schematics/update                0.7.1
rxjs                              6.2.2
typescript                        2.7.2
webpack                           4.8.3

@ryansigg
Copy link

Still seems to be an issue with CLI v 5.0.0.

Fixed with fsevents.
My ng process CPU usage went from 80-100% all the time down to a max of 8% only while compiling otherwise it's at 0 as expected.

@grantlucas
Copy link

This is still definitely an issue on linux in CLI 6.2.2

Angular CLI: 6.2.2
Node: 8.12.0
OS: linux x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.8.2
@angular-devkit/build-angular     0.8.2
@angular-devkit/build-optimizer   0.8.2
@angular-devkit/build-webpack     0.8.2
@angular-devkit/core              0.8.2
@angular-devkit/schematics        0.8.2
@angular/cli                      6.2.2
@ngtools/webpack                  6.2.2
@schematics/angular               0.8.2
@schematics/update                0.8.2
rxjs                              6.3.2
typescript                        2.9.2
webpack                           4.19.1

This is a major issue when running within a Vagrant machine for example. When I run this on my host machine (OSX) everything if fine with fsevents, but using poll in linux on the VM, both cores will steadily be at 80-90%+ usage.

@grantlucas
Copy link

grantlucas commented Sep 19, 2018

@filipesilva Any chance at getting this issue re-opened? It still seems to be an issue.

I had experienced it a few months ago on an older version of CLI and Angular but just finished doing a complete upgrade in the hopes this issue would be resolved in later versions. Sadly it is not.

@grantlucas
Copy link

In my other custom Webpack configs for other watchers, I normally have

        watchOptions: {
            ignored: /node_modules/,
            aggregateTimeout: 300,
            poll: 1000
        },

and that works great within Vagrant, without much CPU usage. Based on what I'm seeing in this repo when searching for watchOptions, I only ever see the poll flag set, nothing for ignored. Is it possible it's trying to watch the whole node_modules folder as well resulting in high CPU usage?

@grantlucas
Copy link

With some local exploration, I've found that adding the following to the watchOptions in the common webpack config resolved CPU usage issues in a Vagrant setup and allowed or 1 second polling without high CPU usage.

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts#L264

        watchOptions: {
            ignored: /node_modules/,
            aggregateTimeout: 300,
            poll: buildOptions.poll
        },

With that, instead of adding more flags for what to put into watchOptions, it'd be great to be able to specify the whole watch options block instead of just the poll option. Just in case this causes issues for other setups.

I can look into setting up a PR but it may take a while as I familiarize myself with the process for this project.

@grantlucas
Copy link

Hopefully the ignored flag can be exposed via #12313

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: investigation Requires some digging to determine if action is needed
Projects
None yet
Development

No branches or pull requests