ng serve uses a lot of CPU %
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.
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.
npm i fsevents should solve this.
Not working on Windows.
installing fsevents solves this issue on mac. Thanks @mseemann
I don't think this issue should be closed. Manually installing fsevents can not be the longterm solution.
Does it make sense to add fsevents to the dependencies of @angular/cli?
@mseemann Thanks a lot!
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
Jose, please keep in mind that node is GC'd so it will happily use available memory and won't collect aggressively until pressured by the OS which doesn't happen if you have a lot of RAM ;-) So unless ng is eating all your memory and your OS starts paging other stuff you should be fine.
On Wed, Jun 7, 2017 at 5:38 PM, Jose Berrocal [email protected] wrote:
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
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/2748#issuecomment-306815246, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH8N0Lg5SAAoyQVRdvVPBVsaZNKX8wiks5sBrX2gaJpZM4KYq8B .
have you tried using task manager to lower the affinity / priority of the process?
@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
@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"})
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');
}
Running under debian, using the ng serve --poll command causes my cpu to spike to %300 (3coresx100)
this is very useful
Can somebody explain why fsevents solves this issue? Posting a solution without an explanation isn't helpful.
What is solution on linux ?
@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.
@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.
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