Large Web site Architecture series: Load Balancing detailed

Source: Internet
Author: User
Tags get ip

In the face of massive user access, high concurrent requests, large amounts of data, high-performance servers, large databases, storage devices, high-performance Web servers, and high-efficiency programming languages such as (Go,scala), we need to consider business splitting and distributed deployment when single-machine capacity reaches the limit. To solve the large-scale web site access, concurrency, high volume of data problems.
From a stand-alone web site to a distributed Web site, it is important to differentiate between business splitting and distributed deployment, the application is split, and deployed to different machines for large-scale distributed systems. Distributed and business splitting solves the problem from centralization to distribution, but there is a single point of issue and access to the unified portal problem for each deployed standalone business, and we can take a redundant approach to solving a single point of failure. Deploy the same application to multiple machines. To solve the problem of accessing the unified portal, we can increase the load balancer device in front of the cluster to achieve traffic distribution.
Load Balancing (Balance), which means that load (work tasks, access requests) are balanced and distributed across multiple operating units (servers, components) for execution. is the ultimate solution for high-performance, single-point-of-failure (high availability), scalability (horizontal scaling).
This article is the first article on load Balancing, which describes the principle of load balancing, Load Balancing classification (DNS load balancing, HTTP load balancing, IP load Balancing, link-layer load balancing, mixed p load balancing). Part of the content is excerpted from reading notes.

Outline
Principle of load Balancing
DNS Load Balancing
HTTP Load Balancing
IP load Balancing
Link Layer Load Balancing
Hybrid p-Load balancing

First, load balancing principle

The expansion of the system can be divided into vertical (vertical) expansion and horizontal (horizontal) expansion. Vertical expansion, from the point of view of a single machine to increase the hardware processing capacity, such as CPU processing capacity, memory capacity, disk and so on, to achieve the improvement of server processing capacity, can not meet the large-scale Distributed System (website), large traffic, high concurrency, massive data problems. Therefore, a scale-out approach is required to accommodate the processing power of large Web services by adding machines. For example: A machine can not be satisfied, then add two or more machines, the joint burden of access pressure. This is the typical cluster and load-balancing architecture:


Application clusters: Deploy the same application to multiple machines, compose a processing cluster, receive requests for load-balanced device distribution, process them, and return the corresponding data.
Load Balancing Device: Distributes user-accessed requests to a processing server in a cluster based on the load-balancing algorithm. (A device that disperses network requests to an available server in a server cluster)
The role of load balancing (problem solved):
1. Solve concurrency pressure, improve application processing performance (increase throughput, strengthen network processing power);
2. Provide failover to achieve high availability;
3. Provide website scalability (extensibility) by adding or reducing the number of servers;
4. Security protection; (do some filtering on the load balancer device, black and white list etc.)

Second, load Balancing classification

According to the implementation technology, it can be divided into DNS load balancing, HTTP load balancing, IP load Balancing, link layer load balancing and so on.

2.1DNS Load Balancing

The first load balancing technology, using domain name resolution to achieve load balancing, in the DNS server, configure multiple A records, these A records corresponding to the server constitutes a cluster. Large Web sites are always partially using DNS resolution as the first level of load balancing. Such as:


Image

Advantages
Simple to use: Load balancing work to DNS server processing, eliminating the hassle of load balancing server maintenance
Improve performance: can support address-based domain name resolution, resolved to the nearest user server address, can speed up access to improve performance;

Disadvantages
Poor availability: DNS resolution is a multilevel resolution, new/modified DNS, parsing time is long, during the parsing process, the user access to the site will fail;
Low scalability: DNS Load Balancing control in the domain name vendor, it can not do more to improve and expand;
Poor maintainability: Also does not reflect the current running state of the server, the number of supported algorithms, can not distinguish between server differences (not based on the state of the system and service to determine the load)

Practical advice
DNS is used as the first-level load balancer, a record corresponds to an internal load-balanced IP address, and the request is distributed to the real Web server through internal load balancing. Generally used in Internet companies, complex business systems are not suitable for use. Such as:

2.3 IP Load Balancing

The network layer is load balanced by modifying the request destination address.
After the user requests the packet, arrives at the Load Balancer server, the Load Balancer server obtains the network packet in the operating system kernel process, obtains a real server address according to the load balancing algorithm, then modifies the request destination address to, obtains the real IP address, does not need passes through the user process processing.
After the real server processing is completed, the response packet goes back to the Load Balancer server, the Load Balancer server, and then modifies the packet source address to its own IP address, which is sent to the user's browser. Such as:


IP load Balancing, the real physical server is returned to the Load Balancer server, there are two ways:
(1) The Load Balancer Server modifies the source address while modifying the destination IP address. Set the packet source address to its own disk, which is the source address translation (Snat).
(2) The Load Balancer server acts as a gateway server for the real physical server cluster.

Advantages:
(1) It is better to distribute the data in kernel process than in the application layer;
Disadvantages:
(2) All request responses need to go through the Load Balancer server, the maximum throughput of the cluster is limited by the bandwidth of Load balancer server NIC;

2.4 Link Layer Load Balancing

The data link layer of the communication protocol modifies the MAC address for load balancing.
Data distribution, do not modify the IP address, refers to the modification of the target MAC address, configure the real physical server cluster all machine virtual IP and Load Balancer server IP address consistent, to not modify the source address and destination address of the packet, for data distribution purposes.
The actual processing server IP and data request destination IP consistent, do not need to go through the Load Balancer Server for address translation, the response packet can be directly returned to the user browser, to avoid load Balancing server network card bandwidth becomes a bottleneck. Also known as Direct route mode (DR Mode). Such as:


Advantages: good performance;
Cons: Complex configuration;
Practice Recommendation: Dr Mode is currently the most widely used load balancing method.

2.5 Mixed-load balancing

Due to the differences in hardware devices, sizes, and services provided in multiple server farms, it is possible to consider the most appropriate load balancing method for each server farm. Then again load-balancing or clustering among the multiple server farms to provide services to the outside world (i.e., as a new server farm) for optimal performance. This approach is called hybrid load balancing.
This approach is sometimes used in situations where the performance of a single equalization device does not satisfy a large number of connection requests. is currently a large-scale Internet company, commonly used in the way.
Way one, such as:


The above pattern is suitable for the scene with static and dynamic separation, and the reverse proxy server (cluster) can play the role of caching and dynamically requesting distribution, when the static resource is cached on the proxy server, it is returned directly to the browser. If the dynamic page requests a later application load balancer (application cluster).
Mode two, such as:


Above mode, suitable for dynamic request scene.
Because of the mixed mode, according to the specific scene, flexible collocation of various ways, the above two methods for reference only.
Sharing is a joy and a process of personal growth.

Three, load Balancing algorithm

Common load balancing algorithms include, polling, random, least link, source address hash, weighting, etc.

3.1 Polling

Distribute all requests, in turn, to each server, which is appropriate for the same scenario as the server hardware.
Advantage: The number of server requests is the same;
Disadvantage: Server pressure is not the same, not suitable for the server configuration of different circumstances;

3.2 Random

Requests are randomly assigned to each server.
Advantages: easy to use;
Disadvantage: not suitable for different machine configuration scenarios;

3.3 Minimum Links

The request is assigned to the server with the fewest number of connections (the server that currently handles the fewest requests).
Advantages: According to the current request of the server processing situation, dynamic allocation;
Disadvantage: The algorithm is relatively complex, it needs to monitor the server request connection number;

3.4 Hash (source address hash)

Based on the IP address hash calculation, get IP address.
Advantage: Forward requests from the same IP address to the same server during the same session, and implement session stickiness.
Disadvantage: The session is lost after the target server is down;

3.5 weighting

On the basis of polling, random, least-link, Hash ' Algorithms, the load server is allocated by weighting the way.
Advantages: According to the weight, the number of requests to adjust the forwarding server;
Cons: use is relatively complex;

Four, hardware load balancing

The use of hardware to achieve load balancing, is generally a separate load balancer server, expensive, general local tyrants class companies can consider, industry-leading has two, F5 and A10.
Using hardware load balancing, consider several aspects:
(1) Functional considerations: full support for all levels of load balancing, support a comprehensive load balancing algorithm, support global load balancing;
(2) Performance considerations: General software load balancing support to level 50,000 concurrency has been difficult, hardware load balancing can support
(3) Stability: Commercial hardware load balancing, after a good rigorous testing, from a large-scale use, in the stability of high;
(4) Security Protection: Hardware equalization equipment In addition to load balancing function, but also has a firewall, anti-DDoS attacks and other security functions;
(5) Maintenance angle: Provide a good maintenance management interface, after-sales service and technical support;
(6) Local tyrants company: F5 Big Ip Price: 15w~55w range; A10 Price: 55w-100w;
Disadvantages
1) The price is expensive;
2) poor expansion capacity;

Summary

(1) General hardware load balancing also to do the dual-machine high availability, so the cost will be relatively high.
(2) Internet companies generally use open source software, so most applications use software load balancing, and partly hardware load balancing.
For example, an Internet company, is currently using several F5 to do global load balancing, internal use of nginx and other software load balancing.

Large Web site Architecture series: Load Balancing detailed

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.