Nginx load balancing algorithm and implementation of

  1. algorithm

1.1 Polling (Round Robin)

The polling algorithm each request sent in turn to each server. The figure, a total of six client generates a request 6, six requests in order (1, 2, 3, 4, 5, 6). Finally, (1, 3, 5) the request will be sent to the server 1, (2, 4, 6) the request will be sent to the server 2.

.

The algorithm is suitable for almost every server performance scenarios, if there are differences in the presence of performance, then the poor performance of the server may not bear much of the load. Below, the performance of the server 2 is worse than a server, the server 2 may not bear much load.

.

1.2 WRR (Weighted Round Robbin)

WRR is based on polling, according to the difference in performance of the server, the server is given a certain weight. For example, in FIG., The weight value of 1 is given to the server 5, the server 2 to the right is given a value of 1, then (1, 2, 3, 4, 5) request is sent to the server 1, (6) requests 2 is sent to the server.

.

1.3 Least Connection (least Connections)

Since the connection request is not the same each time, or Weighted Round Robin polling, it may make a big number of currently connected server, another server connected to a plurality of small, causing load imbalance. For example, the drawing, (1, 3, 5) request is sent to the server 1, but (1, 3) is disconnected quickly, this time only (5) requests a connection to the server; (2, 4, 6 ) request is sent to the server 2, they have not disconnected the connection, continues to run, the server 2 will assume much load.

.

Least connections algorithm is to send the request to the least recently connected to the server number. For example, in FIG, 1 is currently connected to the server the minimum number, then the request will be sent 6 to the server 1.

.

1.4 weighted least connections (Weighted Least Connection)

On the basis of the minimum connection, according to the performance of the server for each server is assigned a weight, and then re-calculate the number of connections per server can handle according to the weights.

.

1.5 stochastic algorithm (the Random)

Random the request sent to the server. And polling algorithm similar to the algorithm is more suitable for almost server performance scenarios.

.

Published 33 original articles · won praise 0 · Views 847

Guess you like

Origin blog.csdn.net/ninth_spring/article/details/104752630