"ng build --prod" can consume all available RAM

Bug #1863921 reported by Chris Sharp
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Evergreen
Status tracked in Main
3.10
Fix Released
Medium
Unassigned
3.9
Fix Released
Medium
Unassigned
Main
Fix Released
Medium
Unassigned

Bug Description

Found when installing stock-ish master servers for feedback fest. When running the "ng build --prod" step on a server with 4GB RAM/1 GB swap, the process is halted with the easy-to-miss message "Killed":

39% building 245/247 modules 2 active ...eg2/node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js??ref--18-0!/home/opensrf/Evergreen/Open-ILS/src/eg2/node_modules/@ngtools/webpack/src/index.js!/home/opensrf/Evergreen/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ngfactory.jsKilled

Increasing swap to 4GB on each server resolved the immediate issue, but further research shows that this is not an unheard-of issue in NodeJS/Angular projects:

https://github.com/angular/angular-cli/issues/1652

Apparently, garbage collection can be explicitly controlled with the "max-old-space-size" parameter.

https://stackoverflow.com/questions/48387040/nodejs-recommended-max-old-space-size

It would be nice to see confirmation of the issue before making any drastic changes, but perhaps we can document the problem and/or hard-code a sane default somewhere?

Output of "ng --version":

Angular CLI: 8.3.12
Node: 12.13.0
OS: linux x64
Angular: 8.2.11
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.803.12
@angular-devkit/build-angular 0.803.12
@angular-devkit/build-optimizer 0.803.12
@angular-devkit/build-webpack 0.803.12
@angular-devkit/core 8.3.12
@angular-devkit/schematics 8.3.12
@angular/cli 8.3.12
@angular/http 7.2.15
@ngtools/webpack 8.3.12
@nguniversal/express-engine 8.1.1
@schematics/angular 8.3.12
@schematics/update 0.803.12
rxjs 6.5.3
typescript 3.5.3
webpack 4.39.2

tags: added: performance
tags: added: angular
Changed in evergreen:
status: New → Confirmed
assignee: nobody → Jane Sandberg (sandbergja)
Revision history for this message
Jane Sandberg (sandbergja) wrote :

I'm curious if the new option to use esbuild rather than webpack in Angular 14 might help (https://blog.angular.io/angular-v14-is-now-available-391a6db736af), once we do that upgrade (bug 1982376)

Revision history for this message
Jane Sandberg (sandbergja) wrote :

Thanks for this report and research, Chris! I've seen the same in VMs that don't have a lot of memory, and can confirm that explicitly setting max-old-space-size can get things working again.

Figuring out a sensible default seems difficult, so I've opted for the docs approach.

Branch here: user/sandbergja/lp1863921_ng_build_prod -- I also took the opportunity to update our install docs from `ng build --prod` to `ng build --configuration="production"` to avoid a deprecation warning.

tags: added: pullrequest
Changed in evergreen:
assignee: Jane Sandberg (sandbergja) → nobody
importance: Undecided → Medium
tags: added: documentation
Andrea Neiman (aneiman)
Changed in evergreen:
assignee: nobody → Andrea Neiman (aneiman)
Revision history for this message
Andrea Neiman (aneiman) wrote (last edit ):

Pushed to master through rel_3_9. Thanks Jane & Chris!

Changed in evergreen:
milestone: none → 3.11-beta
tags: added: signedoff
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.