Ubuntu 18.04 out of the box from AWS is not setup properly to support Redis.

Enable Overcommit Memory

login via SSH

sudo vim /etc/sysctl.conf

Add the following to the end of the file and save.

# VM for Redis
vm.overcommit_memory=1

Reboot the server.

Disable Huge Pages

From: https://techexpert.tips/ubuntu/ubuntu-disable-transparent-huge-pages/

login via SSH

sudo vim /etc/systemd/system/disable-thp.service

Add this to the file:

[Unit]
Description=Disable Transparent Huge Pages (THP)
DefaultDependencies=no
After=sysinit.target local-fs.target
[Service]
Type=oneshot
ExecStart=/bin/sh -c 'echo never | tee /sys/kernel/mm/transparent_hugepage/enabled > /dev/null'
[Install]
WantedBy=basic.target

Reload Services

sudo systemctl daemon-reload

Start the created service

sudo systemctl start disable-thp

Verify THP was disabled…

sudo cat /sys/kernel/mm/transparent_hugepage/enabled

If should show…

always madvise [never]

Enable the new service at reboot…

When finished reboot the server.

Configuring Redis Max Memory

The Redis configuration file in /etc/redis/redis.conf should have a max memory limit. If not set Redis will continue to allocate memory until all memory resources are consumed.

This can lead to a catastrophic server failure where the server not longer can respond to ANY requests.

login with ssh

sudo vim /etc/redis/redis.conf

Uncomment (or add) the line
maxmemory = 1g

This will allow Redis to use up to 1GB of RAM.

Since our middleware servers currently (July 2022) run the API codebase (REST endpoint controller) via node + PM2, it requires a decent amount of memory for that application. It should take precedence over the Redis cache. The system also needs about 500M of RAM for OS and overhead.