others-What's the difference among lvs(keepalived) / nginx / haproxy?

1. Purpose

In this post, I would demonstrate what’s the difference among lvs(keepalived) , nginx and haproxy load balancing.



2. The difference

2.1 Difference between LVS and HAproxy

The most important thing that differentiates the two solutions (LVS, HAproxy) is that one is working at layer 4 (LVS) and the other at layer 7 (HAproxy). Note that the layers references are from OSI networking model.

If you understand this, you’ll be able to use one in the right place. For example : if you need to balance based solely on number of connections (let’s say), the layer 4 load balancer should suffice; on the other hand, if you want to load-balancer based on HTTP response time, you’ll need a higher layer kind of LB.

The drawbacks of using a higher level LB is the resource needed (for the same amount of let’s say, traffic). The plusses are obvious - think “packet level inspection”, “protocol routing”, etc - things far more complicated than simple “packet routing”.

The last point I want to make is that HAproxy is userspace (think “far more easy to customize/tweak”, but slower (performance)), while LVS is in kernel space (think “fast as hell”, but rigid as the kernel). Also, don’t forget about “upgrading LVS might mean kernel change - ergo, reboot”…

In conclusion, use the right tool for the right job.


2.2 What is keepalived?

Keepalived provides frameworks for both load balancing and high availability. The load balancing framework relies on the well-known and widely used Linux Virtual Server (IPVS) kernel module, which provides Layer 4 load balancing.

A Linux Virtual Server (LVS) is a cluster of servers which appears to be one server to an outside client. This apparent single server is called here a “virtual server”. … The ipvs code running on the director is the essential feature of LVS.

Keepalived implements a set of health checkers to dynamically and adaptively maintain and manage load balanced server pools according to their health. High availability is achieved by the Virtual Redundancy Routing Protocol (VRRP). VRRP is a fundamental brick for router failover. In addition, keepalived implements a set of hooks to the VRRP finite state machine providing low-level and high-speed protocol interactions. Each Keepalived framework can be used independently or together to provide resilient infrastructures.

In this context, load balancer may also be referred to as a director or an LVS router.

In short, Keepalived provides two main functions:

  • Health checking for LVS systems
  • Implementation of the VRRPv2 stack to handle load balancer failover

Typically, keepalived is used with haproxy as follows:


2.3 Difference amon LVS, HAProxy and Nginx

LVS: is based on layer 4 forwarding HAproxy: It is based on Layer 4 and Layer 7 forwarding and is a professional proxy server Nginx: It is a WEB server, a cache server, and a reverse proxy server, which can do seven-layer forwarding

Difference: Because LVS is based on Layer 4 forwarding, it can only do port forwarding LVS can’t do URL-based, directory-based forwarding.



3. Summary

In this post, I demonstrated how to understand the different load balancing methods like keepalived/nginx/haproxy. That’s it, thanks for your reading.

-->