Introduction to common algorithms for load balancing

王林
Release: 2020-06-16 16:40:13
forward
3935 people have browsed it

Introduction to common algorithms for load balancing

Commonly used algorithms for load balancing:

1. Round-robin

Polling is load balancing A relatively basic and simple algorithm, it does not require additional parameters to be configured. Assuming that there are M servers in the configuration file, the algorithm traverses the server node list and selects one server in each round in node order to handle the request. When all nodes have been called once, the algorithm will traverse again starting from the first node.

Features:

Since each request in this algorithm is assigned to different servers for processing one by one in chronological order, it is suitable for cluster situations with similar server performance, in which each server carries the same load. . However, for clusters with different server performance, this algorithm can easily cause problems such as unreasonable resource allocation.

2. Weighted polling

In order to avoid the disadvantages caused by ordinary polling, weighted polling came into being. In weighted polling, each server will have its own weight. Generally speaking, the larger the value of weight, the better the performance of the server and it can handle more requests. In this algorithm, client requests are allocated in proportion to their weights. When a request arrives, the server with the largest weight is assigned first.

Features:

Weighted polling can be applied to clusters with varying server performance to make resource allocation more rational.

The core idea is to traverse each server node and calculate the node weight. The calculation rule is the sum of current_weight and its corresponding effective_weight. In each round of traversal, the node with the largest weight is selected as the optimal server node. Among them, effective_weight will change with the resource situation and response situation during the execution of the algorithm.

3. IP hash (IP hash)

ip_hash allocates servers based on the hash value of the client IP that makes the request. This algorithm can ensure that all requests sent from the same IP Requests are mapped to the same server, or different IPs with the same hash value are mapped to the same server.

Features:

This algorithm solves to a certain extent the problem of Session not being shared in a cluster deployment environment.

Recommended tutorial: nginx tutorial

The above is the detailed content of Introduction to common algorithms for load balancing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.im
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template