Load Balancing Concepts

The core load balancing ideas the appliance is built on — the vocabulary the rest of this manual assumes.

The Basics

Loadbalancer.org appliances enable two or more servers to be combined into a cluster. This enables inbound requests to be distributed across multiple servers which provides improved performance, reliability and resilience. Appliances can also be deployed as a clustered pair (our recommended solution) which creates a highly-available configuration.

Supported Protocols

Loadbalancer.org appliances are able to load balance virtually any TCP or UDP based protocol including HTTP, HTTPS, FTP, SMTP, RDP, SIP, IMAP, POP, DNS etc.

Layer 4 & Layer 7

Load balancing at layer 4 and layer 7 is supported. LVS (Linux Virtual Server) is utilized at layer 4 whilst HAProxy is used at layer 7.

What is a Service?

A service is key component of any load balancing configuration. It provides an endpoint that clients can connect to. A service is made up of a frontend that defines the floating IP address, protocol and port(s) that the service should listen on, a backend where the load balanced (real) servers and various other settings are configured and an ACL (Access Control List) that connects the frontend and backend together.

What is a Floating IP?

Floating IPs are active on one node at a time and can move or "float" between nodes to enable HA failover. Therefore it’s not possible to configure a floating IP on the same address as an interface. Floating IPs can also be configured to provide a "floating default gateway" for configurations that require the load balancer to be the default gateway such as layer 4 NAT mode.

Load Balancing Algorithms

The Loadbalancer.org appliance supports several different load balancing algorithms. Each has its own advantages and disadvantages and it depends on the specific application which is the most appropriate to use. Usually the default method Weighted Least Connection is a good solution which works well in most situations. The following sections summarize each method supported.

Weighted Round Robin

With this method, incoming requests are distributed to Real Servers in a sequential manner relative to each Real Server’s weight. Servers with a higher weight receive more requests. A server with a weight of 200 will receive 4 times the number of requests than a server with a weight of 50. Weightings are relative, so it makes no difference if Real Server #1 and #2 have weightings of 50 and 100 respectively or 5 and 10.

Weighted Least Connection

With this method, incoming requests are distributed to Real Servers with the fewest connections relative to each Real Server’s weight. Servers with a higher weight receive more requests. A server with a weight of 200 will receive 4 times the number of requests than a server with a weight of 50. Again, weightings are relative, so it makes no difference if Real Server #1 and #2 have weightings of 50 and 100 respectively or 5 and 10. This is the default method for new VIPs.

Destination Hashing

With the method, requests are distributed to Real Servers by looking up the destination IP in a static hash table. This algorithm is designed for use with web proxies and is supported with layer 4 DR mode Virtual Services only. For more information on this method, please refer to Modifying a Layer 4 VIP.

First (Layer 7 Services Only)

With this method, the first server with available connection slots receives the request. The servers are chosen from the lowest numeric identifier to the highest which defaults to the server’s position in the farm. Once a server reaches its maxconn value, the next server is used.

Source (Layer 7 Services Only)

TBC

Real Server Feedback Agent

To compliment the methods above, Loadbalancer.org appliances also support Real Server agents. This permits the load balancing algorithm to be dynamically modified based on each Real Server’s running characteristics. For example, one Real Server could have a run-away process that is consuming excessive CPU resources or RAM. Without the agent, the load balancer has no way of knowing this and would continue to send requests to the overloaded server based on the algorithm selected. With the agent installed on the Real Server, feedback is provided to the load balancer and the algorithm is then adjusted to reduce requests that are sent to that server. For more information, please refer to Server Feedback Agent.

Layer 4 vs Layer 7

A fundamental choice when setting up the load balancer is whether to configure the services at layer 4 or layer 7.

The Basics

At layer 4 the primary protocols used are TCP and UDP. These protocols are not aware of upper level protocols such as FTP, HTTP, HTTPS, DNS, RDP etc. Therefore the load balancer can only make load balancing decisions based on details available at layers 4 and below such as port numbers and IP addresses. At layer 7, the load balancer has more information to make load balancing related decisions since more information about upper level protocols is available.

Layer 7 load balancing uses a proxy at the application layer (HAProxy). Requests are terminated on the load balancer, and the proxy generates a new request which is passed to the chosen Real Server.

Performance

Due to the increased amount of information at layer 7 and the fact that a proxy is in use, performance is not as fast as at layer 4. If raw throughput is a primary concern, then layer 4 is probably the better choice.

Persistence

Persistence (aka affinity or sticky connections) is the ability to ensure that a specific client connects back to the same server within a specific time limit. It is normally required when the session state is stored locally on the Real Server rather than in a separate database. At layer 4, Source IP persistence is the only option. At layer 7, additional methods are available such as HTTP cookie persistence where the load balancer sets a cookie to identify the session and Microsoft Connection Broker where the load balancer is able to utilize the redirection token for reconnecting users to existing sessions.

Real Server Changes

For layer 4 DR mode, the "ARP Problem" must be solved - for more information, please refer to DR Mode Considerations. For layer 4 NAT mode, the default gateway on each Real Server must be the load balancer. For layer 4 SNAT mode and layer 7 SNAT mode the Real Servers do not need to be changed in any way.

Transparency

Transparency refers to the ability to see the originating IP address of the client. For layer 4 DR mode and NAT mode, connections are transparent. For layer 4 SNAT mode and layer 7 SNAT mode, the IP address of the load balancer is recorded as the source address (for Layer 7 SNAT mode, this can also be set to a user configured address). For layer 7 SNAT mode, additional configuration steps can be taken to force the client IP to be logged. Options include using TProxy to re-write the source address or by enabling support for X-Forwarded-For or Proxy Protocol headers. For more information, please refer to Transparency at Layer 7.

Other Considerations

Does the Application Cluster Correctly Handle its own State?

Load balancers work most effectively if the application servers are completely stateless. This means that if an application server (i.e. Real Server) fails and is automatically taken out of the cluster, then all current user sessions will be transferred to other servers in the cluster without users needing to re-authenticate to the application.

Web based applications are inherently stateless and are an ideal candidate for load balancing. However, do your web servers store files and other information on local drives?

  • Images (jpeg, png, gif etc.)

  • Files (html, php, asp etc.)

If so, these files need to be on shared storage or they need to be replicated to all nodes in the cluster.

Replication Solutions for Shared Data

On Linux systems, Rsync can be used to replicate files. On Windows systems Rsync can also be used, although the Robocopy command may be preferred. Typically, content is uploaded to one primary server and then replicated to the other servers in the cluster.

Solutions for Session Data

Standard ASP and PHP session data is stored locally by default, leaving your session data in a local store will prevent you from implementing seamless application server fail-over in your cluster. If an application server fails, all the local session data will be lost and users will need to re-authenticate and possibly lose shopping baskets etc.

This problem can be resolved by implementing a shared persistent data store for the cluster. This is usually achieved using a shared backend database.

What if the Application is not Stateless?

Some protocols require state to be maintained such as:

  • SSH

  • FTP

  • SMTP

Also, it may not be an option to modify HTTP/HTTPS based application to handle shared session data.

For these cases persistence can be used. Transparent fail-over will no longer be possible, but increased capacity and manageability are still worthwhile benefits of implementing a load balancer.

Default Persistence Options

For layer 4, source IP address persistence can be used and is enabled by default for all new Virtual Services.

For layer 7, the following persistence options are supported:

  • Source IP Address

  • Application Cookie

  • HTTP Cookie

  • HTTP Cookie and Source IP

  • X-Forwarded-For

Objectives & Outcomes

It’s important to have a clear understanding of the objectives and required outcomes to ensure a successful load balancer implementation. Are you looking for increased performance, reliability, ease of maintenance or all three?

Performance

A load balancer can increase performance by allowing multiple commodity servers to handle the workload of one application.

Availability

Running an application on one server introduces a single point of failure. Utilising a load balancer to present multiple servers improves application availability but moves the point of failure to the load balancer. To mitigate this, multiple nodes should be deployed. For more information, please refer to Configuring High Availability.

Maintenance

Using the appliance, servers can be brought on and off line to perform maintenance tasks, without disrupting users.

In order to achieve all three objectives, the application must handle persistence correctly. For more information, please refer to Does the Application Cluster Correctly Handle its own State?.

Loadbalancer.org Terminology

Load Balancer

An IP based traffic manager for server clusters.

Service

The main building block used to configure load balanced services. It defines the IP address clients connect to, which Real Servers are load balanced and other settings such as health check options, persistence options and timeout settings.

Real Server

The actual backend server being load balanced. Multiple Real Servers are associated with a Virtual Service.

Floating IP

The Floating IP Address is automatically created whenever a Virtual Service is configured, the floating IP address is the same as the VIP address. It enables services to be moved between the Primary and Secondary appliance.

WebUI

Web User Interface. Used to configure and manage the appliance.

Layer 4

Part of the seven layer OSI model. Also a descriptive term for load balancing methods that routes packets based on TCP/IP header information.

Layer 7

Part of the seven layer OSI model. Also a descriptive term for a proxy based load balancing method that distributes packets based on the entire TCP/IP header and also the payload information at the application layer.

DR Mode

Direct Routing (aka DSR/Direct Server Return) is a standard layer 4 load balancing technique that distributes packets by altering only the destination MAC address of the packet.

DNAT Mode

Destination Network Address Translation is a standard layer 4 load balancing technique that changes the destination of packets to and from the VIP (external subnet to internal cluster subnet).

Layer 4 SNAT Mode

Source Network Address Translation - similar to DNAT mode but also modifies the source address of all outgoing traffic to be the load balancer.

Layer 7 SNAT Mode

Source Network Address Translation - the load balancer acts as a proxy for all incoming & outgoing traffic.

SSL Termination

The SSL certificate is installed on the load balancer in order to decrypt HTTPS traffic on behalf of the cluster. Traffic from the load balancer to the Real Servers can also be encrypted if required (aka SSL bridging).

MASQUERADE

Descriptive term for standard firewall technique where internal servers are represented as an external public IP address. Sometimes referred to as a combination of SNAT & DNAT rules.

One-Arm

The load balancer has one physical network card connected to one subnet.

Two-Arm

The load balancer has two interfaces connected to two subnets - this can be achieved by using two network adapters, or by creating VLANs on a single adapter.

ens33

The first Ethernet interface.

ens34

The second Ethernet interface.

ens35

The third Ethernet interface.

ens36

The fourth Ethernet interface.