Skip to content
Search

HAProxy

lastmod 2022-09-28created 2016-06-027 edits

Balance Options

For load balancing, the round robin method is generally used. The load balancing algorithms available for the option are listed below.

roundrobin
Distributes sequentially (up to 4128 connectable servers) / each server is used in turn according to its weight / the fairest algorithm when processing times are evenly distributed
static-rr
Distributes according to the weight assigned to each server
leastconn
Distributes to the server with the fewest connections
source
Distributes by hashing the client IP, divided by the weights of the running servers
uri
Distributes by hashing the requested URI, divided by the weights of the running servers (hashed by the URI's length or depth)
url_pattern
For HTTP GET requests, checks whether a specific pattern is present and distributes to the server that matches the condition (no condition -> roundrobin)
hdr
Distributes only when the condition specified by hdr(<name>) is present in the HTTP header (no condition -> roundrobin)
rdp-cookie
Distributes according to the RDP cookie of the TCP request

Using Docker Swarm

versions: '3'

services:
  dockerexample:
    image: neonkid/dockerexample
    ports:
      - 3000
    environments:
      - SERVICE_PORTS=3000
    deploy:
      replicas: 20
      update_config:
        parallelism: 5
        delay: 10s
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 120s
    networks:
      - web

  proxy:
    image: dockercloud/haproxy
    depends_on:
      - dockerexample
    environment:
      - BALANCE=leastconn
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 80:80
    networks:
      - web
    deploy:
      placement:
        constraints: [node.role == manager]

networks:
  web:
    driver: overlay

Swarm HAProxy Ingress

See also

Favorite site

author Zer0 sitemap