What settings on HAProxy are needed to work with AWS ALB (Application Load Balancer)?

Currently we have 200 containers (several different applications) running in a mesomarathon cluster. This is behind HAproxy instances and runs over HTTP / HTTPS.

Internet β†’ AWS ELB β†’ HAProxy β†’ Dock Containers

Now we have a requirement to make one existing application for working on the WEBSOCKET protocol. We are thinking of adding a new AWS ALB to achieve this. Therefore, the setting will look like

(WebSocket) Internet --> new AWS ALB --> HAProxy --> Docker containers (HTTP/S) Internet --> AWS ELB --> HAProxy --> Docker containers 

What configuration do we need to make HAproxy work with the current HTTP / S, as well as with the new WEBSOCKET?

+5
source share
2 answers

The server can handle 65,536 sockets per IP address. So the number can be easily increased by adding additional network interfaces to the server. Meanwhile, it is extremely important to keep track of how many connections are present on the server. Once the limit is exceeded, you can have many problems with other TCP connections (for example, no, you can connect to the server via ssh). So it’s a good idea to restrict WS to node inside your application code.

For HAProxy to handle more than 65 thousand connections, we must go through the following steps:

  • Create a bunch of private IP addresses. To do this, select your Amazon Instance β†’ Actions β†’ Network β†’ Manage Private IP Addresses. We have added 3 IP addresses: 192.168.1.1, 192.168.1.2, 192.168.1.3. Just remember that the IP must be on the same subnet as your real application server.
  • Connect to your HAProxy instance via SSH and run the following commands:

    $> ifconfig eth0:1 192.168.1.1

    $> ifconfig eth0:2 192.168.1.2

    $> ifconfig eth0:3 192.168.1.3

This will add 3 virtual network interfaces to the instance.

  1. Configure HAProxy. Here is the section from the haproxy.cfg file for 3 hosts that accept WS connections:

    listen erlang_front: 8888

     mode http balance roundrobin timeout connect 1s timeout queue 5s timeout server 3600s option httpclose option forwardfor server xxxxx-1 192.168.0.1:8888 source 192.168.1.1 server xxxxx-2 192.168.0.2:8888 source 192.168.1.2 server xxxxx-3 192.168.0.3:8888 source 192.168.1.3 

Now HAProxy can handle more than 65,536 WebSocket connections, and the connection limit can be easily increased by adding virtual network interfaces. In addition, it can establish new connections pretty quickly.

Also see this blog post

0
source

It looks like it might be useful for you to use the new network load balancer instead of the classic elastic load balancer or application load balancer.

NLB can handle (according to AWS) 10 million requests per second and supports long-term connections.

-1
source

Source: https://habr.com/ru/post/1270195/


All Articles