How do I resolve the increase in swap activity in my ElastiCache instances?

2 minute read
0

I want to resolve the increase in swap activity in my Amazon ElastiCache instances.

Short description

ElastiCache runs on Linux. Operating system (OS) factors, such as the version and activity patterns, control swap behavior. Fluctuation in swap usage is an expected behavior. If there isn't enough available RAM when the system moves pages between the disk and RAM, then swapping issues occur.

The following reasons cause the Linux OS to relocate memory pages to swap:

  • 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 available instance memory, then Linux swaps data from the memory to disk to free up space. To determine whether a node is under pressure, review the FreeableMemory and SwapUsage Amazon CloudWatch metrics.

A zero value in the FreeableMemory metric indicates that a node is under memory pressure. For the SwapUsage metric, a value that's greater than the FreeableMemory value indicates that a node is under memory pressure.

Because Redis and Memcached are in memory caches, swap activity slows down your application. If a node is swapping because of memory pressure, then scale up to a larger cache node type. You can also set a reserved memory parameter for Redis or a connection overhead parameter for Memcached.

Linux swaps infrequently accessed memory to disk

Linux might use swaps when an ElastiCache node isn't under memory pressure. To increase memory efficiency, Linux swaps infrequently used memory pages to disk. This 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 confirm that the amount of swap that's used doesn't exceed 300 MB.

Related information

Host-level metrics

Which metrics should I monitor? (Amazon ElastiCache for Redis)

Which metrics should I monitor? (Amazon ElastiCache for Memcached)

AWS OFFICIAL
AWS OFFICIALUpdated 20 days ago
4 Comments

Hello,Khaliluddin_S.

You have mentioned that "It's a best practice to review the SwapUsage metric to verify that the amount of swap used doesn't exceed 300 MB". I wonder if you could kindly tell me why it is "300 MB", and what should I expected once SwapUsage has ever exceeded 300 MB? Thanks in advance.

Tankie
replied 8 months ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied 8 months ago

You have mentioned that "It's a best practice to review the SwapUsage metric to verify that the amount of swap used doesn't exceed 300 MB". I wonder if you could kindly tell me why it is "300 MB"

Question: Is it relative based on the memory of the instance or this is fixed limit applicable for all instance type ?

Harshal
replied a month ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied a month ago