NixOS upgrades bring memory pressure. Investigate: Enable ZRAM? Use Swap?
To save money on infra, we have been changing some AWS EC2 hosts to smaller instances (see, for example, privatestorageops!379).
They run fine, with one big exception: Whenever we are upgrading software, NixOS uses a lot of RAM and sometimes crashes the VMs.
Last recently, this happened with production Matomo end of last week, and, to my chagrin, after the same procedure worked fine on the same-sized staging setup.
Apart from reverting to bigger machines, we can try to conserve memory.
One way is enabling ZRAM: Similar to swap, memory that is currently not in active use is compressed. This report says it "can double/triple RAM without much speed penalty (great for limited memory systems)".
Another way would be making sure we have swap enabled on these machines. Usually, when a server begins to thrash / use swap, it's mostly game over; But since the NixOS upgrades usually only occur once a week and all memory is freed after the upgrade is complete, I'd accept the intermittent performance penalty.
TBD:
- See whether these machines have swap enabled, and whether we have enough disk space to enable it.
- Check if NixOS has an easy and reliable way to enable ZRAM and try it out on staging.