Operations 4 min read

How LVS Chooses Servers: Exploring Round‑Robin, Weighted and Least‑Connection Algorithms

This article explains how Linux Virtual Server (LVS) distributes incoming requests among backend machines, detailing four common scheduling algorithms—simple round‑robin, weighted round‑robin, least‑connections, and weighted least‑connections—along with example code and a visual illustration of request allocation.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How LVS Chooses Servers: Exploring Round‑Robin, Weighted and Least‑Connection Algorithms

LVS (Linux Virtual Server) decides which real server will handle a client request using various scheduling algorithms. Below are the most commonly used methods.

1. Round‑Robin

The simplest algorithm cycles through the servers in the cluster, assigning each new request to the next server regardless of its current load. It works best when all servers have similar performance.

i = -1;
i = (i + 1) mod n;

2. Weighted Round‑Robin

Each server is assigned a weight reflecting its processing capacity. Requests are still distributed in a round‑robin fashion, but a server is selected only when its weight permits, allowing more powerful servers to receive more traffic.

For example, with three servers weighted 4, 3, 2 and nine incoming requests, the distribution follows the weighted sequence.

Below is a JavaScript simulation of the algorithm:

// JavaScript example (simplified)
var weights = [4,3,2];
var servers = ['A','B','C'];
var i = -1;
for (var req=0; req<9; req++) {
  i = (i + 1) % servers.length;
  // decide based on weight...
}
LVS scheduling illustration
LVS scheduling illustration

3. Least Connections

This dynamic algorithm sends a request to the server that currently has the fewest active connections. It is similar to round‑robin but better suited when server capacities differ.

The scheduler tracks each server’s connection count, selects the minimum, increments the count for the chosen server, and decrements it when the connection ends or times out.

4. Weighted Least Connections

Combines the concepts of weight and connection count. For each server, the value connections / weight is computed; the server with the smallest result receives the next request, balancing load according to both capacity and current usage.

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 balancingRound RobinScheduling AlgorithmsLVSLeast Connections
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

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.