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

Memory usage of node process for ng test/serve is very high #5613

Closed
kolbma opened this issue Mar 24, 2017 · 60 comments
Closed

Memory usage of node process for ng test/serve is very high #5613

kolbma opened this issue Mar 24, 2017 · 60 comments

Comments

@kolbma
Copy link

kolbma commented Mar 24, 2017

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ △ \ | '
\ / _ | | | | |/ _ | '
| | | | | | |
/ ___ | | | | (
| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
@angular/cli: 1.0.0-rc.2
node: 6.10.1
os: win32 x64 (Win10)
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0-rc.2
@angular/compiler-cli: 2.4.10

Repro steps.

Run npm test or npm start which runs ng test / ng serve

The log given by the failure.

Memory usage for each node process is between 600MB and 1000MB. That's a lot, I think, although the application is really small (about 500 lines of code).

Desired functionality.

I can't believe that this high memory usage is intended.

Mention any other details that might be useful.

Do you need a dump file?

@filipesilva
Copy link
Contributor

This has been the case for a while, so in that sense it is intended (e.g. not a bug).

I do agree it's quite a bit and there's probably room for improvement there.

@timruffles
Copy link

timruffles commented Mar 27, 2017

With a reasonably large project I get OOM when the process hits Node's memory limit. Since you can't set Node's memory limit via env var, I have to dig around manually to run the tests.

ƒ ng test

<--- Last few GCs --->

   42309 ms: Mark-sweep 1364.9 (1435.8) -> 1364.7 (1435.8) MB, 1728.3 / 0.0 ms [allocation failure] [GC in old space requested].
   43288 ms: Mark-sweep 1364.7 (1435.8) -> 1364.7 (1435.8) MB, 978.5 / 0.0 ms [allocation failure] [GC in old space requested].
   44370 ms: Mark-sweep 1364.7 (1435.8) -> 1366.6 (1413.8) MB, 1081.1 / 0.0 ms [last resort gc].
   45379 ms: Mark-sweep 1366.6 (1413.8) -> 1368.9 (1413.8) MB, 1009.0 / 0.0 ms [last resort gc].

@kolbma
Copy link
Author

kolbma commented Mar 27, 2017

@timruffles Yes, the memory usage of npm install is also crazy. But this is another topic.

Is the problem that developers don't understand that JSON-objects in memory need memory and isn't just a virtual, magic document from outer space ;-)

@buu700
Copy link
Contributor

buu700 commented May 14, 2017

Running two concurrent ng serves, I had to increase the memory allocated for Docker from 2 GB to 4 GB just to prevent OOMing. This seems really wrong. Is it loading all of node_modules into RAM or something?

@kpudlik
Copy link

kpudlik commented May 15, 2017

Agree. @angular/cli makes my laptop's fans getting crazy.
I've made comparison of pure Webpack setup, create-react-app and @angular/cli and cli is much worse. Any ideas?

@reppners
Copy link
Contributor

This issue is rather old but I've never had a problem on my local setup until recently updating to CLI v1.3.0

It's running on macOS Sierra 10.12.6 and I have to restart ng serve twice a day because node runs out of memory.

The apps size is about 150 components, no big dependencies other than angular material.

@russelltrafford
Copy link

Since there isnt a suitable recent ticket I can +1, im adding that we're having major issues with Jenkins and angular builds taking up way too much memory and causing the no response in 20000ms issue. From looking at the resources, excessive RAM usage from angular cli and npm seems to be the cause during builds

@kolbma
Copy link
Author

kolbma commented Oct 1, 2017

No solution for angular but I'm using now npm 5.4.2 and this version and some before (5.x.y) are much faster and use less memory.

@johnbwoodruff
Copy link

I also have gotten to where I'm constantly restarting my ng serve due to it running out of memory, and my app isn't very large at all, perhaps 30 components, plus Angular Material.

@voznik
Copy link

voznik commented Nov 18, 2017

image
I'm on @angular/cli v 1.5.0 | node 6.12.0 | npm 5.4.2, and ng serve uses 1.1Gb of RAM... what the hell?!

@changan712
Copy link

Any update? Same issue using 'ng serve --hmr'

@hansl hansl added feature Issue that requests a new feature and removed type: enhancement labels Jan 30, 2018
@hansl hansl removed their assignment Feb 6, 2018
@leonetosoft
Copy link

Same problem here !!!!
When you make changes it will swell !!! It starts low, every time it changes some file it increases.

memory usage

@pckrishnadas88
Copy link

Same issue. system freezes.

@valmirphp
Copy link

+1

@leonetosoft
Copy link

This softens the situation: node --max_old_space_size=512 "./node_modules/@angular/cli/bin/ng" serve
Put in packeage.json in scripts....

@frankiDotNet
Copy link

Same here, working with latest version of all.. With about 15 components and 3 services getting 3 gb of ram consumption an browser is freezing..

@RyanZhou713
Copy link

+1, Same issue with me, every day need close and open Angular, my project based on Nebular ngx-Admin, about 30~40 components, any update on this issue?
Version details as below
Node: 8.11.3
OS: win32 x64
Angular: 6.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.8.3
@angular-devkit/build-angular 0.8.3
@angular-devkit/build-optimizer 0.8.3
@angular-devkit/build-webpack 0.8.3
@angular-devkit/core 0.8.3
@angular-devkit/schematics 0.8.3
@angular/cdk 5.2.5
@angular/cli 6.2.3
@ngtools/webpack 6.2.3
@schematics/angular 0.8.3
@schematics/update 0.8.3
rxjs 6.2.2
typescript 2.7.2
webpack 4.20.2

@mmakarios
Copy link

Memory running out was happening to me because I had a serializer file with a function returning an object with several entries.

function(obj) {
  return {
    key1: value1,
    key2: value2,
    ...
    key30: value30,
    ...
}

Also, some features in VS Code stopped working just by opening this file. After examining its Process Explorer, VS Code's tsserver process was utilizing an enormous amount of memory (it was exploding when opening that file and not decreasing after closing it). So in my case the issue was probably related to TypeScript.

I fixed just using Object.assign() instead of returning an object directly.

@laflaneuse
Copy link

+1

@skylarmb
Copy link

I have a similar issue. I cant run typescript compilation after deploy on an EC2 instance with 1gb of ram (900+mb free), even with all optimizations turned off. It runs out of memory and crashes almost instantly.

              "optimization": false,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": false,
              "namedChunks": false,
              "aot": false,
              "extractLicenses": false,
              "vendorChunk": false,
              "buildOptimizer": false

@RodolpheGohard
Copy link

same issue here,

When running ng serve, I have two processes which will eat up 1.3 and 1.4GB, which makes 2.7GB for both ! this is ridiculously too large, it freezes my system eventually, since I also have a backend, a browser and an IDE to run.

system is ubuntu 18,
command: node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve --host 0.0.0.0

@skylarmb
Copy link

@RodolpheGohard have you tried lowering max_old_space_size? 8192mb is 8gb... Try --max_old_space_size=1024 maybe? I was able to get it working on a system with 1gb of ram (t2.micro) that was previously crashing due to out of memory by setting --max_old_space_size=900 (900mb), it just made the build process slower.

@WESquad-oldmember
Copy link

WESquad-oldmember commented Oct 30, 2019

Same here, I'm currently on Ubuntu 19.10, Angular CLI: 8.3.14, Node: 12.6.0.

Just after rebooting my PC, starting VScode and doing "ng s" I get this almost 700MB hungry basterd showing up ! with this bad boy and Chrome running at the same time, my PC just starts to beg for forgiveness and mercy...

ng_ram_hungry_basterd

@ankurpowar
Copy link

ankurpowar commented Nov 7, 2019

Generating new App with ng new TestApp consuming around 300 mb when served with no changes

@simontol
Copy link

simontol commented Nov 8, 2019

I can't believe this is still an issue after 2 years. My PC literally freezes when running 'ng serve'.
Fedora 31 on Intel 8 core Xeon 8gb ram + SSD.

@dssagar93
Copy link

2019 anyone? I have windows 10 and the moment I run ng serve --open to run Angular app, the VS Code suddenly works slow, Visual Studio 2017 also becomes slow and the node.exe CPU usage is super high.

@blogcraft
Copy link

With Angular 9 right around the corner, let's see if this problem gets worse or better.

@vpsnotas
Copy link

This softens the situation: node --max_old_space_size=512 "./node_modules/@angular/cli/bin/ng" serve
Put in packeage.json in scripts....

A little bit better on my mac but using --max_old_space_size=1024

@hamed6
Copy link

hamed6 commented Dec 20, 2019

my app angular 8.3(few components) is run on ubuntu 16.4 with 2g memory and im facing the same issue. its being killed, and that's killing me...

@gotwig
Copy link

gotwig commented Dec 31, 2019

I try to use Angular together with Glitch.com (something like stackblitz) but I cant use it with ng serve because it regulary exceeds the memory limit of 512 mb so its not usable.

Any idea what I can do? I want to use glitch.com to work on private projects from everywhere...

The app exceeded the memory limit. Stopping and pausing for 15 seconds.

I use latest Angular (9)

@Rahut-5771
Copy link

This is really depressing, I am struggling from 2 days to deploy my app on aws t2 micro. I have memory swap of 4GB and still it;s giving the same error.

@hryuk
Copy link

hryuk commented Feb 9, 2020

With Angular 9 the memory usage decreased significantly during ng serve, at least for me.

@blogcraft
Copy link

My Node.js is using 1.9 GB of RAM when debugging Angular 8.1.1 😞

Update: My Node.js is now using 2.6 GB of RAM when debugging Angular 8.2.6 😞

Update: My Node.js is now using 1..5 GB of RAM when debugging Angular 9.0.0 😮

@wartab
Copy link

wartab commented Feb 24, 2020

Since Angular 9, our project reached an all time high of 2.3 GB for ng serve and 0.7 GB for a process type-checker-worker. Webstorm using 2 GB on startup and the JS language service of Webstorm using 1.1 GB, we're already at over 6 GB RAM used just for basic client sided development tools. Add Chrome with Dev tools, Visual Studio, and SQL Server and fairly good developer machines with 16GB RAM are starting to tank a severe performance hit.

I can remember Angular's processes using way less RAM a year ago. I'm unsure what exactly caused this to progressiveley increase.

@blogcraft
Copy link

Since Angular 9, our project reached an all time high of 2.3 GB for ng serve and 0.7 GB for a process type-checker-worker. Webstorm using 2 GB on startup and the JS language service of Webstorm using 1.1 GB, we're already at over 6 GB RAM used just for basic client sided development tools. Add Chrome with Dev tools, Visual Studio, and SQL Server and fairly good developer machines with 16GB RAM are starting to tank a severe performance hit.

I can remember Angular's processes using way less RAM a year ago. I'm unsure what exactly caused this to progressiveley increase.

Tried using only VS Code instead of WebStorm and Visual Studio?

@joschne
Copy link

joschne commented Mar 11, 2020

Is starting to get problematic in our company: Computers with not more than 8 GB RAM start to freeze. We're using Angular CLI 8.3.22. I hope Angular 9 makes it better.

According to @blogcraft it gets a little better, according to @wartab it's getting worse.

Is there more people having experience with 9?

@frankiDotNet
Copy link

frankiDotNet commented Mar 11, 2020

For me it is getting better (not good).Release build time earlyer was over 3 minutes with 3.5 memory of ram usage. Now under 2 minutes and 2gb with angular 9.
I have a big project with devextreme coponents. I am using jetbrains rider, but also if I use the command console (windows) there is no difference. Thinking that rider uses 2.5 and Angular 2.5 for build, at this moment I would not recommend a machine under 12 gb. Sad but for me no other chance...

@arielmoraes
Copy link

Could a team member or a top colaborator from the Angular project give us some detailed information about why that happens? That RAM usage is horrible for some software houses.

@Sarfarazsajjad
Copy link

macbook pro 2015 core i7, 16gb ram, fans going crazy with ng build, ng test, ng server etc.
@angular/cli 8.3.21,

also most ci platforms have 4gb ram limit, so our tests and builds are failing on pipeline

@blogcraft
Copy link

macbook pro 2015 core i7, 16gb ram, fans going crazy with ng build, ng test, ng server etc.
@angular/cli 8.3.21,

also most ci platforms have 4gb ram limit, so our tests and builds are failing on pipeline

I use Azure DevOps for CI, maybe give it a shot?

@vrkansagara
Copy link

I think Angular core team has to come up with solution otherwise they are going to loosing developer.Because developer can not buy machine every year but they can learn new thing every year.
image

@intellix
Copy link
Contributor

intellix commented May 17, 2020

the CPU usage is insane as well. I've got ng serve running locally in the background and haven't touched the frontend for at least an hour, just left it idle. It's using 90% CPU and I'm not even using it.

This is on a MBP 15" Late 2019

@timothyBrake
Copy link

the CPU usage is insane as well. I've got ng serve running locally in the background and haven't touched the frontend for at least an hour, just left it idle. It's using 90% CPU and I'm not even using it.

This is on a MBP 15" Late 2019

High CPU usage (constant 90% on ng serve) on a MacBook Pro can be solved by installing newest version of fsevents
The high memory usage is still a mystery though so any response from dev team would be great.

@alan-agius4
Copy link
Collaborator

Hi all,

This thread has been open for 3 years now and was originally reporting using Angular CLI 1.0.0-rc.2.

Since then, a lot of things changed in the entire eco-system, while memory usage might still be high when using ng serve and ng test today. It's very unlikely that the root cause is the same as that of 3 years ago.

Having all the feedback in a single thread makes it hard to get meaningful reports, or to inform people of what versions the regressions that affect them were fixed.

High memory usage can have a number of root causes ranging from a Node.js (EX version 11 is known to have memory related bugs), compiler, application architecture, NGCC or Angular CLI. Unfortunately without a reproduction (Even shared privately) it would be almost impossible to find and solve the root cause.

Thus, my recommendation would be to open new issue and provide all the information requested in the issue template, that way we will be able to action the issue.

Thank you all for your understanding.

@wartab
Copy link

wartab commented May 26, 2020

Imagine closing the issue being the only response to this increasingly worsening problem.

@alan-agius4
Copy link
Collaborator

alan-agius4 commented May 26, 2020

@wartab, on my machine a new Angular projects takes 366Mb for the main process + 169Mb for the forked checker during ng serve, of course as an application get bigger and bigger so does the memory requirements.

Screenshot 2020-05-26 at 12 05 10

Unfortunately, there is no silver bullet that solves all memory issues, and every problem here might very well have a different root cause. Yet there isn't enough information in a given comment to help use understand how we can reproduce the issue. So please help us to help you, by filling a new issue providing all the information required or even better a reproduction.

We definitely want to get to the bottom of this, but we cannot investigate and eventually fix something which we cannot reproduce.

@arielmoraes
Copy link

arielmoraes commented May 26, 2020

@alan-agius4 in your perspective, is it normal a new project consuming almost 500 Mb of RAM? I think you've just reproduced the issue.

@SchnWalter
Copy link
Contributor

SchnWalter commented May 26, 2020

@arielmoraes, there isn't much Angular CLI can do abut this. I would say that 500MB is resonable given the complexity of the Angular CLI.

Also, you can see that the TypeScript compiler can consume a GB on medium-sized projects, just search for high memory usage in the TypeScript issue queue.

If you are still not convinced, you can build the demo file from Building your first TypeScript file handbook, it consumes 152MB. So, I would say that 500MB for Angular CLI is very good. If you want to convince your self, here's a repo:

https://github.com/SchnWalter/typescript-memory-usage

That repo only provides this file:

function greeter(person) {
  return "Hello, " + person;
}

let user = "Jane User";

document.body.textContent = greeter(user);

If you run npm run build:log-memory-usage (linux/mac required for memory usage stats), you will see this output:

> typescript-memory-usage@1.0.0 build:log-memory-usage /workspace/playground/typescript-memory-usage
> /usr/bin/time --verbose -- npm run build
> typescript-memory-usage@1.0.0 build /workspace/playground/typescript-memory-usage
> tsc greeter.ts
Command being timed: "npm run build"
User time (seconds): 2.68
System time (seconds): 0.08
Percent of CPU this job got: 160%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.72
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 152856
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 39940
Voluntary context switches: 1976
Involuntary context switches: 343
Swaps: 0
File system inputs: 0
File system outputs: 16
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0

And you will see that the command has consumed 152MB for compiling the code above plus one comment. Yes code comments do count, so do blank lines, because they are represented in the TypeScript Abstract Syntax Tree as complex object instances.

@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 Jun 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests