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

Out of memory on Pi Zero W (512 MB) #118

Open
alexrudd2 opened this issue Nov 14, 2023 · 4 comments · May be fixed by #120
Open

Out of memory on Pi Zero W (512 MB) #118

alexrudd2 opened this issue Nov 14, 2023 · 4 comments · May be fixed by #120

Comments

@alexrudd2
Copy link
Owner

          Trying this on my Pi Zero W (512 MB) results in running out of memory:
pi@plotter:~/saxi $ npm install 
> [email protected] prepare
> rimraf dist && npm run build

> [email protected] prebuild
> npm run lint

> [email protected] lint
> eslint --cache --ext .ts,.tsx src

> [email protected] build
> tsc && webpack --mode=production

<--- Last few GCs --->

[24524:0x5f5eaf0]   253322 ms: Scavenge 123.1 (128.7) -> 123.0 (128.7) MB, 14.28 / 0.00 ms  (average mu = 0.554, current mu = 0.129) allocation failure; 
[24524:0x5f5eaf0]   253382 ms: Scavenge 123.1 (128.7) -> 123.0 (129.2) MB, 22.51 / 0.00 ms  (average mu = 0.554, current mu = 0.129) allocation failure; 
[24524:0x5f5eaf0]   257224 ms: Mark-Compact 123.4 (129.2) -> 123.0 (129.7) MB, 3464.13 / 0.00 ms  (average mu = 0.404, current mu = 0.145) allocation failure; scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
Aborted
npm ERR! code 134
npm ERR! path /home/pi/saxi
npm ERR! command failed
npm ERR! command sh -c rimraf dist && npm run build

npm ERR! A complete log of this run can be found in: /home/pi/.npm/_logs/2023-11-14T11_21_59_716Z-debug-0.log

version info:

pi@plotter:~/saxi $ which npm ; npm --version
/home/pi/saxi/node-v20.5.1-linux-armv6l/bin/npm
9.8.0
pi@plotter:~/saxi $ git rev-parse HEAD ; git status
53b14a09a4134dd0f19dbc9aa820c63e10e22537
On branch main
Your branch is up to date with 'origin/main'.

Originally posted by @osresearch in #85 (comment)

@alexrudd2
Copy link
Owner Author

switching to a2ac49f didn't fix the memory exhaustion, so I added a 1GB swap file, and that didn't work either which surprised me. it looks like tsc doesn't fill all available RAM by default, so I added an explicit heap size (1 GB == 1024KB) and it was able to complete:

diff --git a/package.json b/package.json
index 7400185..cb6f1c6 100644
--- a/package.json
+++ b/package.json
@@ -22,7 +22,7 @@
     "prebuild": "npm run lint",
     "lint": "eslint --cache --ext .ts,.tsx src",
     "build": "npm run build:server && npm run build:ui",
-    "build:server": "tsc",
+    "build:server": "NODE_OPTIONS='--max-old-space-size=1024' tsc",
     "build:ui": "node --experimental-modules build.mjs",
     "prepare": "rimraf dist && npm run build",
     "prestart": "npm run build",

Originally posted by @osresearch in #85 (comment)

@alexrudd2
Copy link
Owner Author

@osresearch @jedahan do you see any downside to committing the 1GB heap size?

I'm using a Mac and/or RPi 4 so it doesn't affect me. Should be able to test on an Orange Pi Zero 2W next week

@jedahan
Copy link
Collaborator

jedahan commented Nov 14, 2023

I think we'd want to mention somewhere how to create a swap file and why its needed. I will confirm on my pi zero that setting these options fixes tsc. ETA tomorrow morning

@jedahan
Copy link
Collaborator

jedahan commented Nov 20, 2023

I can confirm this fixed npm run build:server on my pi zero w

@alexrudd2 alexrudd2 linked a pull request Nov 27, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants