Basic algorithms for load Balancing

Source: Internet
Author: User
Tags gcd greatest common divisor nginx load balancing

The basic algorithms for load balancing are as follows (refer to F5 products):

    • Random: Load Balancing method randomly distributes the load to each available server, selects a server by the random number generation algorithm, and sends the connection to it. While many of the balanced products support this algorithm, its effectiveness has been challenged until the server's uptime is seen to be heavy.
    • Polling: The polling algorithm assigns each new connection request to the next server in order, eventually splitting all requests to all servers. Polling algorithms work well in most cases, but if load-balanced devices are not fully equal in terms of processing speed, connection speed, and memory, the effect is better.
    • Weighted polling: In this algorithm, the number of connections accepted by each machine is allocated by weight ratio. This is an improvement to the ordinary polling algorithm, such as you can set: The third machine is capable of processing twice times the first machine, then the load balancer will allocate twice times the number of connections to the 3rd machine.
    • Dynamic polling: Similar to weighted polling, however, weight values are based on ongoing monitoring of individual servers and are constantly updated. This is a dynamic load balancing algorithm that allocates connections based on the real-time performance analysis of the server, such as the current number of connections per node or the fastest response time for a node.
    • Fastest algorithm: The fastest algorithm is based on the fastest response time allocation connection in all servers. This algorithm is particularly useful in environments where servers span different networks.
    • Minimum connection: The system assigns the new connection to the server with the fewest number of current connections. This algorithm is very effective in the environment where the computing ability of each server is basically similar.
    • Observation algorithm: The algorithm uses the minimum connection algorithm and the fastest algorithm to implement load balancing. The server gets a score based on the current number of connections and response time, the higher the score, the better the representation, and the more connections.
    • Pre-judgment algorithm: This algorithm uses the observation algorithm to calculate the score, but the pre-judgment algorithm will analyze the change trend of the score to determine whether the performance of a server is improving or decreasing. Servers with improved trends will get more connections. The algorithm is suitable for most environments.

Performance Tuning Community Dynatrace shared customer stories in its blog, and e-commerce sites crashed several times during peak holiday traffic, and the SQL optimization and load Balancing algorithm was used to solve the problems. First of all, analyze the slowest database statements and perform performance optimizations such as adding indexes. It also optimizes the connection pool size to meet the demand at peak times. The enterprise then changes the load Balancer's algorithm from Round-robin to Least-busy.

Related articles:

E-commerce website outage Case analysis

ASP. NET Session State Partitioning

ASP. NET Session state partitioning using the state Server Load balancing

Analysis of Nginx Load balancing

Round Robin Scheduling

Using System;Using System.Collections.Generic;Using System.Linq;Using System.Runtime.CompilerServices;Using System.Text;Namespace loadbalancer{PublicClass LoadBalance {<summary>Lock Object</summary>PrivateStaticReadOnlyObject locker =NewObject ();<summary>Server Weights List</summary>PrivateStatic list<Int> weightlist =New list<Int> ();<summary>Current index</summary>PrivateStaticint currentindex;<summary>Current weight</summary>PrivateStaticint currentweight;PrivateStaticint maxweight;<summary>Greatest common divisor</summary>PrivateStaticint gcd;Static LoadBalance () {currentindex =-1; currentweight = 0;Gets a list of server weights from the configuration file Weightlist = Getweightlist (); Maxweight = Getmaxweight (weightlist); GCD = GETMAXGCD (weightlist); }PrivateStatic list<Int> getweightlist () {list<int> list =New list<Int> (); List. ADD (3); List. ADD (1); List. ADD (1); List. ADD (4); List. ADD (1); List. ADD (7);return list; } [MethodImpl (methodimploptions.synchronized)]PublicStaticint Start () {Lock (Locker) {Int? Iweight = Roundrobin ();if (iweight! =NULL) {Return (int) Iweight; }return weightlist[0]; } }<summary>Get greatest common divisor</summary><param name= "List" > the Int collection to find </param><returns> returns the greatest common divisor in the collection </returns>PrivateStaticint GETMAXGCD (list<Int> list) {list. Sort (New Weightcompare ());int iminweight = weightlist[0];int gcd = 1;for (int i = 1; i < iminweight; i++) {BOOL Isfound =Trueforeach (int IweightIn list) {If (iweight% i! = 0) {Isfound =FalseBreak } }if (isfound) gcd = i; }return GCD; }<summary>Gets the maximum weight in the server weight collection</summary><param name= "List" ></param><returns></returns>PrivateStaticint Getmaxweight (list<Int> list) {int imaxweight = 0;foreach (int IIn list) {if (Imaxweight < i) imaxweight = i; }return imaxweight; }PrivateStaticint? Roundrobin () {while (true) {Currentindex = (currentindex + 1)% WeightList.Count; if (0 = = currentindex) {currentweight = CURRENTWEIGHT-GCD; if (0 >= currentweight) {currentweight = Maxweight; if (currentweight = 0) return null;}} if (Weightlist[currentindex] >= currentweight) {return weightList[ Currentindex]; }}}} public class weightcompare:icomparer<int> { Span class= "KWRD" >public int Compare (int x, int y) {return x-y; }}} 

go from: http://www.cnblogs.com/shanyou/archive/2012/11/09/2763272.html

Basic algorithm for load balancing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.