I have been using HAProxy as a Redis load balancer of sorts within a 
Docker container which is part of a simple highly available Redis setup. 
I run one instance of HAProxy on each app node and the app communicates 
to Redis through the HAProxy instance running on the same node. The only 
simple way to make sure this traffic is not crossing machines is to use 
a Unix socket instead of TCP. Here is a simple visual explanation of why 
sockets are used:

With sockets:
   App1 --> Proxy1 ----> (Server1,Server2)
   App2 --> Proxy2 --/
   App3 --> Proxy3 -/
   App4 --> Proxy4 /

Without sockets (TCP - round-robin DNS):
   (App1,App2,App3,App4) --> (Proxy1,Proxy2,Proxy3,Proxy4) --> 
(Server1,Server2)

So using sockets ensures that I'm not needlessly consuming LAN bandwidth 
between the App and Proxy. Due to the way the container scheduler works 
there is not a simple way of making sure that the app only uses the 
proxy that is on the same machine to prevent it from hitting the network.

Now, to my bug report. I've noticed a few times after letting my test 
cluster sit idle for several days that when I come back to use it the 
socket no longer works (client reports "Connection refused" error), even 
though HAProxy is still running and it does work over TCP. The socket 
file is present and is a socket type, it just can't be connected to. If 
I restart HAProxy it works, but obviously I don't want it to require 
random restarts to stay up. There is nothing in the logs indicating an 
error.

Test method:

$ socat - UNIX:/run/magento/redis-cache.sock
2017/02/27 19:45:20 socat[55] E connect(5, AF=1 
"/run/magento/redis-cache.sock", 31): Connection refused

Version: 1.6 - just upgraded to 1.7.2 and started testing.

Here is my full HAProxy config:

----------------------------------------------------------------------------------
global
   log 127.0.0.1 local0 notice

defaults
   mode tcp
   log global
   timeout client     1h
   timeout server     1h
   timeout connect 1000

listen stats
   bind *:1936
   mode http
   stats enable
   stats hide-version
   stats realm Haproxy\ Statistics
   stats uri /
   stats auth ***:***

frontend redis-unix
   bind /run/magento/redis-cache.sock mode 777
   default_backend redis

frontend redis-tcp
   bind *:6379
   default_backend redis

# The tcp-check will ensure that only reachable master nodes are 
considered up.
backend redis
   balance first
   option tcplog
   option tcp-check
   tcp-check send info\ replication\r\n
   tcp-check expect string role:master
   default-server inter 5000 downinter 5000 fastinter 1000 rise 2 fall 3 
maxconn 256 maxqueue 128
   server node1 10.81.128.1:6379 check
   server node6 10.81.128.6:6379 check
----------------------------------------------------------------------------------

Thanks!
Colin

Reply via email to