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
Reboot the server.
Disable Huge Pages
login via SSH
sudo vim /etc/systemd/system/disable-thp.service
Add this to the file:
Description=Disable Transparent Huge Pages (THP)
ExecStart=/bin/sh -c 'echo never | tee /sys/kernel/mm/transparent_hugepage/enabled > /dev/null'
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.