What for?
A single web server has limits: it handles only so many requests, and if it fails, the site is gone. If you set up several identical servers, someone has to distribute the clients. That is the load balancer: clients only know its address (e.g. via DNS www.firma.example), and it passes each connection to one of the servers behind it.
Methods
| Method | How | Good for |
|---|---|---|
| Round robin | in turn | equally strong servers, short requests |
| Least connections | to the server with the fewest open connections | requests of different length |
| Source hash | by the client's address | sessions that must stay with the same server |
With a weight per server (1–100) a stronger server gets more connections: weight 3 means three times as many as weight 1. leyoNET spreads them evenly like nginx («smooth weighted round robin»): with 3:1 «A A B A», not «A A A B». Least connections divides the open connections by the weight.
Health checks
The load balancer regularly checks whether the servers answer, here every 2 s with a TCP connection setup. After two failures a server counts as down and gets no new connections, after two successes it is back. Clients notice nothing of the failure.
Reverse proxy on layer 4
leyoNET works like HAProxy in TCP mode: the load balancer accepts the client's TCP connection itself and opens a second connection to the chosen server. In between it passes the data on unchanged. That is why the server sees the load balancer as the sender, not the client. Real layer 7 load balancers put the client address into an HTTP header for this (e.g. «X-Forwarded-For»).
The load balancer itself is thus a single point that can fail. Large networks therefore have two that share an address, as with VRRP (redundant gateway).
In leyoNET
In the shop under Servers → Load balancer (ready configured) or on a server under Services → Load balancer: port, method, health check and the servers behind it. In the simulation the table shows «up» or «down», open and total connections for each server. The packet list shows two TCP connections per request; the web server reports the load balancer as the client in its console.
How to do it in leyoNET
The same text as in the app’s help (F1 key).
Load balancer
A load balancer sits in front of several identical servers (e.g. web servers). Clients only know its address; it spreads the connections over the servers behind it. The group carries more load, and if a server fails, the others take over.
- In the shop under Servers → Load balancer, or on a server under Services → Load balancer: enter the port (e.g. 80) and the servers behind it.
- Round robin: in turn. Least connections: to the server with the fewest open connections. Source hash: the same client always to the same server.
- Weight (1–100) per server: a server with weight 3 gets three times as many connections as one with 1, e.g. because it is stronger. Round robin spreads them evenly (with 3:1 «A A B A», not «A A A B»).
- Health check: every 2 s the load balancer opens a TCP connection to each server. After 2 failures a server gets no new connections, after 2 successes it is back.
- The load balancer works as a reverse proxy on layer 4: it accepts the connection itself and opens a second one to the server. The packet list therefore shows two TCP connections, and the web server reports the load balancer as its client.
If the servers deliver different pages (e.g. «Server 1», «Server 2»), the browser shows the distribution. See also Equal-cost paths (ECMP) (spreading in routing) and Redundant gateway (VRRP) (redundant gateway).
See an example
- Load balancer in front of three web servers
The PCs always open the same address (192.168.1.80). The load balancer passes each connection in turn to Web 1, Web 2 or Web 3 (round robin) and checks every 2 s whether the servers answer.
The browser shows «Web 1», «Web 2», «Web 3» in turn. Load balancer → Services shows the connections per server. Remove the cable of Web 2: after the health check it gets no new connections. Packet list: two TCP connections per request.
“Watch live” opens the network in leyoNET, the simulation runs in a loop. In the app you find it under File → Demo networks, with a step-by-step tour.
Practise
- ★★★☆☆ Web servers in pairs (load balancer) · 2 goals · Worksheet (German)
In leyoNET under Tools → Exercise catalogue. Every exercise checks itself.
What leyoNET simplifies
| Protocol | Layer | Simplification in the simulation |
|---|---|---|
| Load balancer | 4–7 | Reverse proxy on layer 4 (like HAProxy in TCP mode) for one port: round robin, least connections, source hash; health check every 2 s by TCP connection setup (2 failures = out, 2 successes = back); if a server does not answer, another one is tried once; no «X-Forwarded-For» header, no weights, no TLS |
Standards
- RFC 9293 – Transmission Control Protocol (TCP)