I am trying to improve performance (responsivity) of a webserver during rare events of high memory utilization (90%...) where it starts to swap a lot, in order to help manual intervening faster and less error prone. I can't add more RAM to the machine (32G RAM + 6G swap partition).
One way to improve performance in such a situation is using compressed swap caching in RAM, so that the system uses RAM more efficiently and the impact of I/O waits for slow nonvolatile memory decreases.
Older research from 1999 [1] indicates that the faster the CPU compared to I/O operations, the greater the benefits of compressed swap cache and this should get even better as CPUs get faster. It is recommended to use swap compression if using rotational disks.
I wonder whether this advice to increase performance still holds true for servers that have only SSD drives. Here the I/O operations are much faster, so the benefit is lower than with rotational disks.
An implementation of this functionality was introduced in Linux 3.11 via zswap in 2012 [2]. Does anybody have experience with it on a server, is there also a benefit when using purely SSD drives?
[1] https://www.usenix.org/legacy/event/usenix99/full_papers/wilson/wilson.pdf
[2] https://events.static.linuxfound.org/sites/events/files/slides/tmc_sjennings_linuxcon2013.pdf
RAM is still far, far faster than an SSD. You might seen NVMe drives advertised at 3GB/s, remember than RAM in a modern PC can be 20-25GB/s. And those are just sequential speeds, random access times greatly favor RAM over NVMe. You're talking milleseconds vs nanoseconds. SATA SSD's are even slower yet.
Also remember that Apple uses memory compression, and every Mac (except the low end iMacs) use very fast SSDs.
To improve responsiveness on systems that are paging in, prevent them from paging out in the first place:
zswap is something you would need to test yourself, depends on the workload. There is increased overhead to inserting a compressing cache before the swap device, which may hurt response times. Further, zswap is still documented as experimental and lightly tested compared to the possible workloads.
While it may have a benefit, expect to spend several hours tuning, testing, and monitoring how it is doing. Consider instead buying another 32 GB or so of RAM and prevent the page out in the first place.