WP Load Balancing Algorithms | Network and Application Layer | Imperva

Load Balancing Algorithms

Edge SecurityConnection Optimization

What are load balancing algorithms

Effective load balancers intelligently determine which device within a given server farm is best able to process an incoming data packet. Doing so requires algorithms programmed to distribute loads in a specific way.

Algorithms vary widely, depending on whether a load is distributed on the network or application layer. Algorithm selection impacts the effectiveness of load distribution mechanisms and, consequently, performance and business continuity.

Here we will be discussing the pros and cons of several widely used algorithms found in both network and application layer load balancing solutions.

Network vs Application layer

Network layer and application layer algorithms differ in how they’re able to analyze incoming traffic and the criteria they use to distribute traffic loads.

Network layer algorithms Application layer algorithms
Distribution logic Statistical/randomized Data driven
Suitable infrastructure types Symmetrical/even All types
Server load visibility No Yes
Session persistence Yes Yes
Unpredictable load handling No Yes

Network layer algorithms

The main challenge to network layer load balancers is a lack of visibility into traffic flow, limited to information stored in network packet headers. Routing decisions have to be based on only a few factors—primarily source and destination IP data.

Network layer load balancers cannot assess the nature of incoming requests, their expected load generation and available server resources at a given time. A certain amount of guesstimation is needed for them to make routing decisions.

Examples of network layer algorithms include:

  • Round robin – A batch of servers are programmed to handle load in a rotating sequential manner. The algorithm assumes that each device is able to process the same number of requests and isn’t able to account for active connections.
  • Weighted round robin – Servers are rated based on the relative amount of requests each is able to process. Those having higher capacities are sent more requests.
  • Least connections – Requests are sent to the server having the fewest number of active connections, assuming all connections generate an equal amount of server load.
  • Weighted least connections – Servers are rated based on their processing capabilities. Load is distributed according to both the relative capacity of the servers and the number of active connections on each one.
  • Source IP hash – Combines the source and destination IP address in a request to generate a hash key, which is then designated to a specific server. This lets a dropped connection be returned to the same server originally handling it.

While these algorithms are adequate in predictable traffic scenarios, they’re not as effective in dealing with uneven/unexpected server loads.

Application layer algorithms

Application layer load balancers distribute requests based on content of the requests being processed, including its HTTP/S header and message in addition to session cookies. They can also track responses as they travel back from the server, thereby providing data on the load each server is processing at all times.

As opposed to the speculative nature of network load balancing, application load balancing is data driven. This provides the intelligent distribution of incoming requests.

The most notable application layer algorithm is least pending requests (LPR). It monitors pending HTTP/S requests and distributes them to the most available server. LPR can instantly adjust to a sudden influx of new connections while continuously monitoring the workload of all servers within a server farm.

LPR benefits include:

  • Accurate load distribution – Unlike network layer algorithms distributing requests according to preset rules, LPR intelligently selects the server best suited to process an incoming connection in real-time.
  • Request specific distribution – LPR can acknowledge that connection requests take different processing times and distributes load accordingly. As a result, traffic isn’t routed to busy servers.

See how Imperva Load Balancer can help you with high availability .

Choosing the right load balancing algorithm

There are a number of considerations in selecting a load balancing algorithm. Specifically, your choice needs to be able to handle both predictable scenarios (e.g., typical traffic flows), and unpredictable ones (e.g., a sudden request influx that creates a heavy load).

Unpredictable scenarios, which network layer algorithms are incapable of handling, are the most concerning to site operators. Additionally, TTL related delays make network load balancing a less than optimal solution.

Application layer algorithms, on the other hand, help to maintain optimal website performance during both predictable and unpredictable scenarios.