Operations 5 min read

How LVS Powers Million-Connection Load Balancing: Modes, Algorithms, and HA

This article explains why Linux Virtual Server (LVS) can handle millions of concurrent connections by operating in kernel space, outlines its three core forwarding modes (NAT, Direct Routing, TUN), describes the main load‑balancing algorithms, and shows how Keepalived provides high‑availability failover.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
How LVS Powers Million-Connection Load Balancing: Modes, Algorithms, and HA

LVS (Linux Virtual Server) achieves million‑level concurrency because it is a high‑performance Layer‑4 load balancer that runs entirely in the Linux kernel, avoiding the costly user‑space processing required by solutions like Nginx.

Operating at the IP and transport layers, LVS eliminates frequent user‑kernel context switches, dramatically improving throughput.

Since LVS only handles network and transport packets without parsing application‑layer protocols such as HTTP, its processing speed is extremely fast and its performance overhead is minimal, which is the key to supporting high concurrency.

LVS Core Modes

LVS offers three core forwarding modes to suit different scenarios.

NAT mode : suitable for low traffic but imposes higher load on LVS.

Direct Routing (DR) mode : packets bypass LVS after routing, the most commonly used mode that supports million‑level concurrency.

<ol><li>Client → LVS (request)</li><li>LVS → Real Server (direct response to client)</li></ol>

TUN mode : high‑performance cross‑network scenario, ideal for geographically distributed data centers.

Powerful Load‑Balancing Algorithms

LVS supports multiple algorithms, including Round‑Robin (RR), Weighted Round‑Robin (WRR), Least Connections (LC), and Weighted Least Connections (WLC).

RR distributes requests sequentially across servers, suitable when server capacities are similar.

Round Robin diagram
Round Robin diagram

WRR assigns a weight to each server; higher‑weight servers receive more requests.

LC sends new requests to the server with the fewest active connections, providing dynamic load distribution.

Load balancing algorithms diagram
Load balancing algorithms diagram

These algorithms intelligently route traffic based on real‑time server load, ensuring balanced and efficient operation.

High Availability Assurance

Even with strong performance, a single LVS failure would disrupt services. To prevent this, Keepalived is commonly used to provide high availability.

Keepalived implements the VRRP (Virtual Router Redundancy Protocol) and manages a cluster with one master and one or more backup servers.

It continuously monitors the master’s health; if the master fails, Keepalived automatically migrates the virtual IP (VIP) to a backup, maintaining uninterrupted service.

Keepalived high‑availability diagram
Keepalived high‑availability diagram
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

load balancingLinuxLVSkeepalived
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.