我运行的是最小支持的配置:1G 内存和 2G 交换空间。在我看来,重建脚本中的某些内容指示 node.js 使用的内存超过了我拥有的内存,这似乎会抑制垃圾回收并导致大量交换。这是否符合预期?
我注意到控制台日志中出现以下信息:
I, [2024-06-14T15:19:15.613029 #1] INFO -- : cd /var/www/discourse & su discourse -c 'bundle exec rake assets:precompile:build'
Node.js heap_size_limit (504.75) is less than 2048MB. Setting --max-old-space-size=2048 and CHEAP_SOURCE_MAPS=1
...[ConfigLoader]
...[Babel: @embroider/macros > applyPatches]
Stack Exchange 建议这样做不好:
配置的 max-old-space-size 的限制高于机器拥有的总内存量。
…
总之,在一台拥有 2GB 内存的机器上,我可能会将 --max-old-space-size 设置为大约 1.5GB,以便为其他用途留出一些内存并避免交换。
这时我看到有大量的交换活动:
# df -h / ; free ; uptime ; ps auxrc ; vmstat 5 5
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 25G 20G 4.7G 81% /
total used free shared buff/cache available
Mem: 1009140 860952 81820 1104 66368 43068
Swap: 2097144 707016 1390128
15:21:53 up 155 days, 23:02, 2 users, load average: 1.69, 1.85, 1.36
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
message+ 920 0.0 0.1 50192 1872 ? Rs Jan10 5:57 dbus-daemon
root 16979 0.0 0.0 0 0 ? R 14:14 0:02 kworker/u2:2
1000 24317 84.1 71.4 43775512 720984 ? Rl 15:19 2:07 ember
root 24346 0.0 0.3 40100 3468 pts/0 R+ 15:21 0:00 ps
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----\n r b swpd free buff cache si so bi bo in cs us sy id wa st\n 2 1 710656 79768 7712 60940 350 283 586 352 1 2 3 2 90 4 0\n 1 5 798060 65440 3848 52544 21749 19198 23815 19247 3896 16477 30 17 0 52 1\n 0 1 885676 73820 1256 37388 19674 18806 20887 18811 3851 16681 21 20 0 55 3\n 1 0 704056 103080 11512 70892 8414 3910 17269 3914 1855 7618 64 11 0 25 1\n 1 0 693816 95020 11520 70908 1589 0 1589 54 470 1032 95 1 0 4 0\n```
(这是在命令行重建和更新过程中,从大约 3.2.0.beta5-dev(bcb31f79ce) 到 (最新) 3.3.0.beta3-dev(49fdccbb1d)。重建在大约 30 分钟内成功完成。)