我正在尝试在armv7a主机上构建Mattermost,但是Node在Webpack构建期间内存不足。解决该问题的方法似乎应该在max_old_space_size
中设置NODE_OPTIONS
,但是与直觉相反的是,这样做似乎会导致在第一次运行节点时立即使构建失败。
主机具有2G的RAM,但我添加了12G的交换无效。
CPU:Marvell Armada 370 / XP(设备树)(4)@ 1.333GHz
节点:v13.13.0
正常构建时崩溃,大约30分钟后发生:
Building mattermost Webapp
rm -rf dist
npm run build
> mattermost-webapp@0.0.1 build /var/tmp/portage/www-apps/mattermost-server-5.22.0/work/mattermost-server-5.22.0/src/github.com/mattermost/mattermost-server/client
> cross-env NODE_ENV=production webpack --display-error-details --verbose
<--- Last few GCs --->
[17346:0x1e80ee8] 2121678 ms: Mark-sweep 501.2 (506.3) -> 500.7 (506.3) MB, 1640.3 / 0.0 ms (average mu = 0.108, current mu = 0.029) allocation failure scavenge might not succeed
[17346:0x1e80ee8] 2123903 ms: Mark-sweep 501.2 (506.3) -> 500.8 (506.3) MB, 2178.0 / 0.0 ms (average mu = 0.064, current mu = 0.021) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x1468e00]
1: StubFrame [pc: 0x14098a4]
Security context: 0x31940491 <JSObject>
2: /* anonymous */(aka /* anonymous */) [0x9e4bbf89] [/var/tmp/portage/www-apps/mattermost-server-5.22.0/work/mattermost-server-5.22.0/src/github.com/mattermost/mattermost-server/client/node_modules/webpack-sources/l
ib/applySourceMap.js:~58] [pc=0x9c9a9b44](this=0x40f0027d <undefined>,0x4c40d721 <String[2]: e}>,0xa5f1ebcd <Object ...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mattermost-webapp@0.0.1 build: `cross-env NODE_ENV=production webpack --display-error-details --verbose`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mattermost-webapp@0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
添加NODE_OPTIONS=max_old_space_size=4196
时崩溃(立即发生):
make -j4 build
Getting dependencies using npm
npm install
<--- Last few GCs --->
[35:0x1ea1e00] 394 ms: Mark-sweep 1.0 (2.5) -> 0.9 (3.5) MB, 10.7 / 0.0 ms (average mu = 0.724, current mu = 0.096) allocation failure GC in old space requested
[35:0x1ea1e00] 401 ms: Mark-sweep 0.9 (3.5) -> 0.9 (2.0) MB, 6.6 / 0.0 ms (average mu = 0.627, current mu = 0.063) last resort GC in old space requested
[35:0x1ea1e00] 409 ms: Mark-sweep 0.9 (2.0) -> 0.9 (2.0) MB, 8.6 / 0.0 ms (average mu = 0.463, current mu = 0.005) last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x1489e00]
Security context: 0x375c0491 <JSObject>
1: test [0x375c4d6d](this=0x5cfb2121 <JSRegExp <String[#14]: (?:^|\/)\.?\.$>>,0x33167c71 <String[#27]: ../lib/utils/unsupported.js>)
2: /* anonymous */(aka /* anonymous */) [0x375ca1a5] [internal/per_context/primordials.js:23] [bytecode=0x375f6695 offset=28](this=0x4938027d <undefined>,0x5cfb2121 <JSRegExp <String[#14]: (?:^|\/)\.?\.$>>)
3: arguments adap...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
make: *** [Makefile:36: node_modules] Aborted
为什么更改max_old_space_size
会导致Node立即耗尽内存?
编辑:要添加的更多信息...我一直在使用https://github.com/Data-Wrangling-with-JavaScript/nodejs-memory-test作为演示的最小测试用例。似乎Node拒绝将交换空间视为可用内存。例如,如果我运行:
$ node nodejs-memory-test/index.js
它分配到最后一行:
Allocated since start 0.49 GB
崩溃前。如果我运行:
$ NODE_OPTIONS="--max-old-space-size=1024" node nodejs-memory-test/index.js
它成功运行到
Allocated since start 0.98 GB
崩溃之前
但是,如果我跑步:
NODE_OPTIONS="--max-old-space-size=8196" node nodejs-memory-test/index.js
它在死去之前只经过少数几行
Allocated since start 0.01 GB
有人可以帮助我了解发生了什么事吗?