3

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

Ján Lalinský
  • 262
  • 1
  • 10
  • 1
    One thing you might want to evaluate is the configuration of your webserver (and database if you're also running it on the same server). Tuning the configuration for your use cases can free up quite a bit of memory and also speed things up in other ways. For example, having too many server processes running can suck up RAM. Even more drastically you might want to switch to NGINX if you are using Apache. – Bert Oct 04 '19 at 14:54
  • @Bert I am asking about benefits of swap cache in a rare critical situation when rogue processes/attacks eat all the server memory and Linux would start to swap heavily. One can tune and tweak configurations, but from time to time those events will still happen. I'm asking about those rare events, and whether swap compression will help to make them less frequent or more manageable. – Ján Lalinský Oct 05 '19 at 18:53
  • @anx I'm using stock Centos 7 kernel. How would I do that? What do you mean by "compare with reduced web server concurrency"? – Ján Lalinský Oct 05 '19 at 18:55

2 Answers2

3

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.

Bert
  • 2,733
  • 11
  • 12
  • Your're right about the RAM speed, but there is also 1) CPU cost to compression/decompression which may in some situations (perhaps when swapping hard to SSD) get comparable to 2) cost of I/O waits for SSD when ordinary swap is used. Regarding Apple computers, those are desktops/laptops with too little RAM capacity that is hard to expand, so turning on RAM compression does make sense. I'm really interested in benefits of zswap for servers in times of memory exhaustion as opposed to just using ordinary swap. – Ján Lalinský Oct 05 '19 at 19:03
1

To improve responsiveness on systems that are paging in, prevent them from paging out in the first place:

  • Reduce the memory demands of the application
  • Scale out to more instances
  • Scale up to more RAM in instances

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.

John Mahowald
  • 30,009
  • 1
  • 17
  • 32
  • That is a good advice, but I am specifically interested in benefits during times of memory exhaustion. Those will probably always happen no matter how well tweaked the system is, simply because I have no control of all processes and attackers on the server. – Ján Lalinský Oct 05 '19 at 19:06