Preparing the host system for Redis

The Device Portal uses Redis for caching and to handle asynchronous tasks. Redis relies on a few settings that can’t be controlled from within the containers that run the application. If these configurations aren’t in place when a Docker container running Redis starts a warning will be shown on the screen.

Verify if configuration changes needs to be done on your host by running (break with [Ctrl]+c):

docker run --rm redis

The messages you need to check for can look like these:

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.

WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

If you see a warning the instructions needs to be run on the host computer where the Device Portal will be installed.

The second warning above mentions adding a command to /etc/rc.local. If you are using a distribution based on SystemD, such as Ubuntu 20.04 or later, you need to use SystemD instead. For those systems you can create a file in the /etc/systemd/system directory.

[Unit]
Description=Disable Transparent Huge Pages
Documentation=https://redis.io/topics/latency

[Service]
Type=oneshot
ExecStart=/bin/sh -c "/bin/echo never > /sys/kernel/mm/transparent_hugepage/enabled"
ExecStart=/bin/sh -c "/bin/echo never > /sys/kernel/mm/transparent_hugepage/defrag"

[Install]
WantedBy=multi-user.target

Start the new “service”.

systemctl start redis-settings

Also don’t forget to enable the service so that it persists through reboots.

systemctl enable redis-settings

Confirm that the warnings are gone by starting a new Redis container as per the instructions above.