I have an m5a.xlarge running CentOS 7. It has two volumes including the root volume and an extra (for storage). Both are general SSD. The root volume is 60GB general SSD so it has 180 iops. In the top level of the drive, I have a 4GB swap file. Any IOP intensive task is happening on the storage volume. However, we are noticing huge burst IO usage on the root volume periodically which is causing high load averages (20+) and essentially choking out the system. We decided to switch from a file-based swapfile to a memory based swap file using zram because paging-related IO was the only thing we could think of on the root volume that would be causing problems. When we did “swapoff” to drain the swapfile and install zram-based swapping, we noticed huge IO bursts also, so we feel this may have been the issue.
Anyway, my question is whether anyone has experienced this before? After endless reading AWS seems to advocate for a swapfile and many people talk about using swapfiles but no one seems to discuss the IO consequences of having a swapfile on an EBS drive. AWS mentions using the ephemeral drive for swap but we haven’t done that.
Any thoughts on this? Anyone else experience this before?
Thanks guys
EDIT: Thanks for all the replies guys. The naughty boxes are no longer using swapfile on root file system. Instead, I’ve got a swapfile on a zram drive. Kernel seems happy swapping a little bit out of memory and compressing it into the zram swapfile. I really won’t know if the problem is solved until a week goes by without an IO event. To help take pressure off those root drives, we switched them to provisioned IO with 1000 IOPS. IF everything goes well, we’ll switch them back.
Chances are good that you’re simply running out of RAM and no possible location for the swapfile will give acceptable performance. Try disabling swap and see if you end up with tasks getting killed by the OOM killer - and if so, adjust your workload or instance type to fix it.
Swap is there for when you run out of memory. Allocating a fixed chunk of memory for use when you run out of memory seems odd.
I also wouldn’t be surprised if your IOPS problem was caused by having a swap file on the volume. Linux could be paging not recently used memory out to swap in order to use more memory for disk cache , etc. Just by virtue of being an ersatz substitute for RAM, swap is going to incur very high IOPS.
Swap on instance store makes a lot of sense; it’s a lot lower latency (great for swap!) and you don’t care that it’s ephemeral since swap is cleared on reboot anyway.
If you need more memory but are OK on compute, consider switching to r5.blah series of instances.
If you have to manually manage memory utilization on a cloud instance, you’re either working in a very low-budget shop (in which case you’re probably better served by switching to a cheaper provider like Digital Ocean), or you’re doing it wrong.
Keep in mind EBS lets you burst up to 3000 IOPS for a fairly substantial amount of time for volumes smaller than 1 TB. Volumes with 1 TB or more have 3000 IOPS or more on provisioning.
We have a 3 Terabyte database, we never really hit the IOPS limit.
We have always had a problem with the throughput limit.
For example, a full database backup took approximately ten to twelve hours after switching from GP2 to IO1 volume types and changing the instance to m5.4xlarge the backup went to three to four hours.
On a smaller 600 GB database, the problems we saw were not because of the IOPS, the problem was maxing the throughput of the EBS Volume or the throughput of the EC2 instance.
Fair. A lot of that is related to much better network connectivity for io1 storage compared to gp2.
That said, I’m so happy we’ve just straight up used Aurora in my last two places.
As much as I enjoy DBA work, I don’t miss hand managing multi-TB MySQL databases running on bare VMs. Especially when instance retirement notifications roll around.
Linux is not great in low memory situations without swap. When memory pressure gets too high Linux just grinds to a halt. So even a small amount of swap can get you out of trouble.
But it is easy to generate a lot of swap traffic even if you have “spare” memory. Things like memory limits on containers is a common cause. And swapping to EBS can be super painful.
The ephemeral drive instances - like m5ad if you are using an m5a - cost 10-20% more but the local SSD is good for swap and temp files or things like compiling binaries.
Or you can play with the swappiness kernel setting, making it less aggressive.
The server has 16GB of RAM and doesn’t come anywhere close to using up physical memory. I assume the kernel is using swap proactively to take pressure off of RAM.
For the longest time, I ran my servers without swap and haven’t had a problem (since they had enough RAM). I started using swap on low memory boxes for obvious reasons and having that swap volume fixed the problem. When I moved to larger boxes for another client, I kept the swap around because seemed like a good idea. Problem is that the kernel seems to use swap even before you’re out of memory and periodically its incurring large IO costs.
This server has 16GB of RAM and uses maybe 30% of it (not counting buffers). I started including swap space on larger machines because it seemed like a freebie/no-brainer. But it seems that the kernel, seeing this delicious swap, uses it to take pressure off the physical RAM regardless of what level its at. I guess I could adjust that with swappiness.
The first thing I checked was whether anything IO intensive was running and really there isn’t anything. The root volume does almost nothing while the secondary drive is the most active. Once I ruled out any individual cron job that was eating IO, all I was left with was the swap file