Updating discourse - node.js auto-bumped to 2G on a 1G machine

I’m running on the smallest supported config: 1G RAM and 2G swap. It looks to me like something in the rebuild script tells node.js to use more RAM than I have, which it seems suppresses garbage collection and causes a lot of swapping. Is this as it should be?

I noticed this in the console log:

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 suggests this is not good:

The configured max-old-space-size had a higher limit than the total amount of RAM that the machine had.

In summary, on a machine with 2GB of memory I would probably set --max-old-space-size to about 1.5GB to leave some memory for other uses and avoid swapping.

Around this time I see there’s a huge amount of swap activity

# 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-----
 r  b   swpd   free   buff  cache    si    so    bi    bo   in    cs us sy id wa st
 2  1 710656  79768   7712  60940   350   283   586   352    1     2  3  2 90  4  0
 1  5 798060  65440   3848  52544 21749 19198 23815 19247 3896 16477 30 17  0 52  1
 0  1 885676  73820   1256  37388 19674 18806 20887 18811 3851 16681 21 20  0 55  3
 1  0 704056 103080  11512  70892  8414  3910 17269  3914 1855  7618 64 11  0 25  1
 1  0 693816  95020  11520  70908  1589     0  1589    54  470  1032 95  1  0  4  0

(This is during a command line rebuild and update from approx 3.2.0.beta5-dev(bcb31f79ce) to (Latest) 3.3.0.beta3-dev(49fdccbb1d). The rebuild completed successfully in about 30mins.)