Why does swapping occur in ElastiCache?

Last updated: 2022-07-19

I am seeing an increase in Swap activity in my Amazon ElastiCache instances? How do I resolve this?

Short description

ElastiCache runs on Linux Operating System (OS). Swap behavior is controlled by the OS and is influenced by factors such as OS version or activity patterns. It's expected behavior that instances experience fluctuations in swap usage.

Swapping issues occur when there isn't enough available Random Access Memory (RAM) when the system is moving pages between the disk and RAM.

Linux OS proactively relocates memory pages to swap for two main reasons:

  • An ElastiCache node is under memory pressure
  • Linux swaps infrequently accessed memory to disk

Resolution

An ElastiCache node is under memory pressure

If your cache node uses more memory than the instance has available, then Linux swaps data from the memory to disk to free up memory space for use. A FreeableMemory CloudWatch metric equal to zero or a SwapUsage metric that is greater than the FreeableMemory metric indicates a node that is under memory pressure.

Because both Redis and Memcached are in memory caches, swapping slows down your application.

If you see that a node is swapping due to memory pressure, scale up to a larger cache node type. Otherwise, set a Reserved Memory parameter for Redis, or a connection overhead parameter for Memcached.

Linux swaps infrequently accessed memory to disk

Swap might be used when an ElastiCache node isn't under memory pressure because Linux OS proactively moves memory pages that aren't frequently used to swap to increase memory efficiency. This usage is normal kernel behavior and doesn't imply active reading and writing to swap.

It's a best practice to review the SwapUsage metric to verify that the amount of swap used doesn't exceed 300 MB.


Did this article help?


Do you need billing or technical support?