# 05-26 Redis Read error on connection

https://redis.io/topics/clients

# Problem

After a random amount of time (~ 5min) of gateway uptime, the server errors out. The error message is always something like

read error on connection to 127.0.0.1:6379

So far I thought this would be fixable by disallowing clients to time out on failed connections. That does not actually solve the issue though, it just "hides" the error messages. Hotel Trivago wrote an excellent article on their lessons learned dealing with Redis. Below I apply their findings to my server configuration

# Solutions

# Upgrade to PHP 7.4.6 stable

Use newer version of PHP with php-fpm and persistent connections so that there is less overhead with creating connections. PHP 7.4 is better at caching OPcode and handling apache processes. I use an older version of PHP because the place where I work has projects using php 7.2. For testing PHP 7.2 has been okay, but for production environments (how I am basically treating my Windows PC) 7.2 can't keep up. Windows 10 cannot handle PHP-FPM without installing the components of the *AMP stack individually (I need the NTS version of PHP 7.4). I am tired of installing things from stupid .exe installers so I might just give WSL a shot after all which supports PHP-FPM out of the box.

# Tweak Redis config to not do background saves.

Redis is single threaded and gets blocked by background saves. Background save duration is coupled to the incoming traffic load and has O(n) time complexity. Background saves can block Redis for tens of milliseconds while the main connections from the MeasurementController are timing out (incoming at ~50ms intervals). Since I do not care about data persistence across server shutdowns (MySQL already does that), I can just deactivate this. Hotel Trivago's Development Team claims that this helped them. on Redis is truly excellent.

# Further actions

I will try option 2 first and cross my fingers that it will work. If that does not do the trick, I will migrate everything to WSL for this project and use persistent connections.

Last Updated: 11/23/2020, 9:42:47 PM