Distributed:

Distributed architecture: the system is divided into multiple subsystems according to modules. Multiple subsystems are distributed on different network computers to cooperate with each other to complete business processes. Communication between systems is required.

Advantages:

  1. Split the module, use interface communication, reduce the coupling degree between modules.
  2. Divide the project into sub-projects, with different teams working on different sub-projects.
  3. To add functionality, you only need to add a subproject that calls the interfaces of other systems.
  4. Flexible distributed deployment.

Disadvantages:

1. The interaction between systems requires the use of remote communication, and the interface development increases the workload.

2. Some common business logic of each module cannot be shared.

Soa based architecture

SOA: Service-oriented architecture. That is, the project is divided into service layer, performance layer two projects. The service layer contains business logic and only needs to provide services externally. The presentation layer only needs to handle the interaction with the page, and the business logic is implemented by invoking the services of the service layer.

What are the differences between distributed and SOA architectures?

SOA, mainly from the point of view of services, divides the project into service layer and presentation layer.

Distributed, mainly from the perspective of deployment, applications are categorized according to access pressure. The main goal is to make full use of server resources and avoid uneven resource allocation

 

The cluster:

A cluster system is a group of loosely combined server groups that form a virtual server to provide unified services for client users. It is common for this client to access the clustered system without being aware of which server its services are provided by. The purpose of clustering is to achieve load balancing, fault tolerance, and disaster recovery. To meet the requirements of system availability and scalability. Cluster system should have high availability, scalability, load balancing, failure recovery and maintainability. Generally, the same project is deployed on multiple servers.

Common Tomcat cluster, Redis cluster, Zookeeper cluster, database cluster

The difference between distributed and cluster:

Distributed means the distribution of different services in different places. Clustering refers to the concentration of several servers to implement the same service. In a word: distributed work in parallel, cluster work in series.

Each node in the distributed system can be a cluster. A cluster does not have to be distributed.

For example, if there are many people visiting Sina.com, it can set up a cluster, put a response server in the front and several servers in the back to complete the same business. If there are business visits, the response server will check which server is not very heavy and assign it to which one to complete the business. And distributed, in a narrow sense, is similar to a cluster, but it is more loosely organized, unlike a cluster, where there is an organization, one server goes down, other servers can take over. Distributed each node, all complete different business, a node collapsed, which business is not accessible.

Distribution improves efficiency by shortening the execution time of a single task, while cluster improves efficiency by increasing the number of tasks executed per unit time.

For example, if a task consists of 10 subtasks and each subtask takes one hour to execute, it takes 10 hours to execute the task on a server. A distributed scheme is adopted to provide 10 servers, each server is only responsible for dealing with one sub-task, regardless of the dependencies between sub-tasks, and it only takes one hour to complete the task. (A typical representative of this working mode is the Map/Reduce distributed computing model of Hadoop.) The cluster solution also provides 10 servers, and each server can independently handle this task. Suppose 10 tasks arrive at the same time, 10 servers will work at the same time, and an hour later, 10 tasks will be completed at the same time, so that the whole thing is still one task in an hour!

High concurrency:

What are some common ways to handle high concurrency?

Freemaker says that static HTML pages are the most efficient and consume the least, so we try to use static pages on our website, which is the simplest method is actually the most effective method. However, for websites with a large number of contents and frequent updates, we cannot implement them one by one manually, so the common information publishing system CMS emerged. For example, the news channels of various portal sites we often visit, even their other channels, are managed and implemented through the information publishing system. Information publishing system can achieve the simplest information recording into automatically generated static pages, but also with channel management, authority management, automatic capture and other functions, for a large website, have a set of efficient, manageable CMS is essential.

In addition to the portal and information release type of site, for interactive website demanding community type, as static as possible is the essential means to improve performance and real-time of the post within the community, the article is static, when there are updates to static is also extensive use of the strategy, like the hodgepodge of Mop is the use of the strategy, Netease community and so on.

With the HTML static is an efficient way of some caching strategies use, for frequent use in the system database query but content update small applications, consider using HTML static, such as BBS my altar public Settings information, the information management background and the current mainstream BBS can be stored to the database, In fact, a lot of these information is called by the foreground program, but the update frequency is very small, you can consider this part of the content of the background update when static, so as to avoid a large number of database access requests.

2, image separation by the server As we all know, for the Web server, regardless of is the Apache, IIS or other containers, the picture is the consumption of resources, so it is necessary to separate the images with the page, this is basically will adopt the strategy of large website, they all have independent server images, and even a lot of pictures of machine. This architecture can reduce the pressure on the server system to provide page access requests, and can ensure that the system will not crash due to image problems. On the application server and image server, different configuration optimization can be carried out, for example, Apache can configure the ContentType as little as possible. As few loadModules as possible to ensure higher system consumption and execution efficiency.

3, a hash cluster and database Large sites have complex applications, these applications must use the database, so in the face of a large number of access, the bottleneck of database could soon emerge, a database application and will soon be unable to meet at this moment, so we need to use a hash cluster or database.

In terms of database cluster, many databases have their own solutions, Oracle, Sybase, etc., have good solutions, and the Master/Slave provided by MySQL is similar. What KIND of DB you use, refer to the corresponding solutions to implement.

The database cluster mentioned above is limited by the DB type in terms of architecture, cost and scalability, so we need to consider improving the system architecture from the perspective of application. Library table hashing is the common and most effective solution. We installed in the application and application or function module database, different modules for different database or table, and then according to certain strategy on a page or smaller database hash function, such as user table, carried out in accordance with the user ID hash table, so that it can improve system performance in low cost and good extensibility. Sohu BBS is adopted such architecture, set the BBS user, separation and post information database, and then to post, the user shall be carried out in accordance with the plate and the ID hash database and table, finally can be simple configuration in the configuration file can let the system adds a low-cost added database in system performance.

4, cache the term cache technology are in contact with many places to use cache. Caching in website architecture and website development is also very important. Here are the two basic types of caches. Advanced and distributed caching is described later. The architecture of the cache, familiar with Apache can know that Apache provides its own cache module, Squid module can also be used to cache, these two ways can effectively improve the access response ability of Apache. For web program development, the MemoryCache provided by Linux is a common Cache interface, which can be used in Web development. For example, MemoryCache can be called for caching and communication sharing of some data in Java development. Some large communities use such architecture. In addition, in the use of Web language development, various languages basically have their own Cache module and method, PHP has Pear Cache module, Java is more,.NET is not very familiar with, I believe there must be.

5, the mirror image is a large web sites often adopt the way of improving performance and data security, image technology can solve different mesh Collaterals of portal and the regional users access speed difference, the difference between such as ChinaNet and EduNet causes a lot of sites within the education network structures, mirror sites, the data is updated regularly updated or solid. Without going into the technical details of mirroring, there are many specialized off-the-shelf solutions and products to choose from. There are also inexpensive ideas that can be implemented through software, such as tools like Rsync on Linux.

Load balancing load balancing will be the ultimate solution for large web sites dealing with heavy traffic and concurrent requests. Load balancing technology has developed over the years, and there are many professional service providers and products to choose from. I personally have been exposed to some solutions, and there are two architectures for you to refer to.

High availability:

Generally, enterprise-level application systems (especially those of government departments and large enterprises) generally adopt safe software and hardware devices, such as IOE (IBM minicomputer, Oracle data, EMC storage device) series. Generally, Internet companies use PC-level servers (x86), open source databases (MySQL) and operating systems (Linux) to form cheap and highly fault-tolerant application clusters (hardware failure is the norm).

(1) The purpose of the design?

Ensure that server hardware failure services are still available and data is still saved and accessible.

(2) The main means?

① Redundancy and ② failover of data and services:

In the case of services, once a server goes down, the service is switched to another available server.

In the case of data, if a disk is corrupted, the data is read from the backup disk (a synchronous copy of the data is made beforehand).

Highly available services

Highly available service modules provide basic common services for business products, which are often deployed independently and distributed in large sites and invoked remotely by specific applications.

In practice, the following highly available service policies can be referred to:

(1) Hierarchical management: core applications and services have higher priority, such as timely payment of users is more important than whether goods can be evaluated;

② Timeout setting: Set the timeout time of service invocation. Once the timeout time is set, the communication framework will throw an exception, and the application will retry or transfer the request to another server according to the service scheduling policy.

③ Asynchronous invocation: complete asynchronously through message queues to avoid the failure of one service resulting in the failure of the entire application request.

Not all services can be invoked asynchronously, and for calls such as retrieving user information, the response time is longer than the cost. Asynchronous invocation is also not suitable for applications that must confirm the success of the service invocation before proceeding to the next step.

(4) Service degradation: In order to ensure the normal operation of core applications, service degradation is required during peak visits to the website.

There are two ways to degrade: One is service denial, which denies calls from applications with lower priorities to reduce the number of concurrent service calls and ensure the normal operation of core applications. The second is to close the function, shut down some unimportant services, or shut down some unimportant functions within the service, in order to save system overhead and release resources for core application services;

(5) Idempotent design: to ensure that the repeated invocation of the service and the invocation of the same result;

Highly available data

There are two main methods to ensure high availability of data: data backup and failover mechanism;

(1) Data backup: It is also divided into cold backup and hot backup. Cold backup is periodically replicated and cannot guarantee data availability. Hot backup is divided into asynchronous hot backup and synchronous hot backup. Asynchronous hot backup means that data copies are written asynchronously, while synchronous hot backup means that data copies are written simultaneously.

The hot backup mechanism of a relational database is known as the Master/Slave synchronization mechanism. In practice, read/write separation is usually used to access the Master and Slave databases. That is, write operations only access the Master database, and all read operations access the Slave database.

(2) Failover: If any server in the data server cluster goes down, all read and write operations on this server are rerouted to other servers to ensure that data access will not fail.

Website operation monitoring

“Do not allow unmonitored systems to go online.”

(1) Monitoring data collection

① Collecting user behavior logs: collecting logs on the server and client. At present, many websites are gradually developing log statistics and analysis tools based on real-time computing framework Storm.

(2) Server performance monitoring: collect server performance indicators, such as system Load, memory occupancy, disk IO, etc., and judge in time to nip in the wind;

(3) Running data report: collection and report, summary after unified display, the application needs to deal with the logic of running data collection in the code;

(2) Monitoring management

(1) System alarm: the configuration of alarm threshold and the contact information of the personnel on duty, the system alarm, even if the engineer is thousands of miles away, can also be timely notified;

(2) Failure transfer: when the monitoring system finds a fault, it actively notifies the application of failure transfer;

(3) Automatic elegant downgrade: in order to cope with the peak site visits, take the initiative to close some functions, release some system resources, to ensure the normal operation of core application services; — > The ideal state of the flexible architecture of the website

 

  1. Master-slave switch

    It is understood that when a service goes down on one of the machines, it is possible for the service caller to quickly switch to other available services and upgrade from the service to the master service in seconds (a few seconds).

    When the service is recovered, it automatically changes to the secondary service and the primary/secondary service roles are switched. There must be a cost to switching from master to slave, so when the master service is restored, the existing master service is not replaced.

  2. Load balancing

    When the number of service requests is high, one service cannot meet the requirements. In this case, multiple machines are required to provide the same service and distribute all requests to different machines.

    A high availability architecture should have rich load balancing policies and easy ways to adjust the load.

    It can even be adjusted automatically and intelligently. For example, due to machine performance, the response time may be different. At this time, less distribution can be sent to the machine with poor performance to ensure the balance of the response time of each machine.

  3. Easy lateral expansion

    When the number of users is increasing and the existing service cannot bear more users, it is necessary to expand the service. The best way to expand the service is not touching the original service and is transparent to the service callers.

 

Load balancing:

1. What is load balancing?

When the performance of a single server reaches its limit, we can use a cluster of servers to improve the overall performance of the site. Therefore, in a server cluster, one server is required to act as the scheduler, which receives all user requests first, and then assigns the requests to a back-end server for processing according to the load of each server.

In this process, how can the scheduler reasonably allocate tasks to ensure that all back-end servers give full play to their performance, so as to keep the overall performance of the server cluster optimal? This is the load balancing problem.

The following describes how to implement load balancing.

(1) HTTP redirection load balancing.

The advantage of this load balancing scheme is that it is simple;

The disadvantage is that the browser needs to request the server twice each time to complete a visit, poor performance. (2) DNS domain name resolution load balancing

The advantage is that the load balancing work is handed over to DNS, which eliminates the trouble of network management.

The disadvantage is that DNS may cache A records, out of the control of the site. (3) Reverse proxy load balancing.

Advantages are simple deployment;

The downside is that the reverse proxy server is the hub for all requests and responses, and its performance can be a bottleneck. (4) IP load balancing

Advantages: IP load balancing implements data distribution in the kernel process and has better processing performance than reverse proxy balancing.

Disadvantages: The network adapter bandwidth of load balancing becomes the bottleneck of the system.

(5) Data link layer load balancing.

Avoiding the bandwidth of network card of load balancing server becomes the bottleneck, which is the most widely used load balancing method for large websites at present.

HTTP redirection implements load balancing

Process description

When a user sends a request to the server, the request is first intercepted by the cluster scheduler. The dispatcher selects a server according to a certain allocation policy, encapsulates the IP address of the selected server in the Location field of the HTTP response message header, sets the status code of the response message to 302, and finally returns the response message to the browser.

When the browser receives the response message, it parses the Location field and makes a request to the URL, which is then processed by the specified server and returned to the user.

In the process of using HTTP redirection for server cluster load balancing, one server is required as the request scheduler. An operation requires two HTTP requests: one to the scheduling server to obtain the IP address of the back-end server, and the second to the back-end server to obtain the processing result.

Scheduling policy

After receiving a request from a user, the scheduling server selects which back-end server to process the request based on the scheduling policy used by the scheduling server.

  1. Random allocation Policy After receiving a user request, the scheduling server randomly decides which back-end server to use, encapsulates the IP address of the server in the Location attribute of the HTTP response message, and returns it to the browser.
  2. The Polling policy (RR) scheduling server needs to maintain a value that records the IP address of the back-end server that was last assigned. When new requests arrive, the scheduler allocates them to the next server in turn.

Because the polling policy requires the scheduler to maintain a value to record the last assigned server IP, it incurs additional overhead; In addition, because this value is a mutex resource, when multiple requests come in at the same time, the mutex resource needs to be locked to avoid thread safety issues, which reduces performance. A random allocation strategy does not require additional values to be maintained, and thus does not have thread-safety issues, and therefore performs better than polling.

Advantages and disadvantages analysis

Using HTTP redirection to realize the load balancing of server cluster is easy to realize, the logic is relatively simple, but the disadvantages are also more obvious.

In HTTP redirection, the scheduling server only comes into play when the client first makes a request to the web site. After the scheduling server returns the response information to the browser, the subsequent operations of the client are based on the new URL (that is, the back-end server). After that, the browser will not have a relationship with the scheduling server, which may cause the following problems:

  • Because different users have different access times and different page depths, each user exerts different stress on their own back-end servers. However, the scheduling server has no way to know how much pressure the current user will cause to the server during the scheduling, so this way can not realize the true load balancing, but is to evenly distribute the number of requests to each server.
  • If the back-end server assigned to the user fails, and if the page is cached by the browser, the request will be sent to the failed server when the user accesses the site again, resulting in an access failure.

 

DNS Load Balancing

What is DNS?

Before learning about DNS load balancing, you need to learn about DNS domain name resolution.

We know that packets of data use IP addresses to travel around the network, and to facilitate user memory, we use domain names to visit websites. So, before we can access a website through a domain name, we first need to resolve the domain name into an IP address, which is done by DNS. That’s the domain name server.

The requests we submit are not sent directly to the site we want to visit, but first to the domain name server, which resolves the domain name into an IP address and returns it to us. We don’t make a request to an IP until we receive it.

Therefore, the DNS server has a natural advantage. If a domain name refers to multiple IP addresses, the DNS only needs to select one IP address to return to users during domain name resolution to implement load balancing in the server cluster.

The specific practices

First, we need to point our domain name to multiple back-end servers (resolve a domain name to multiple IP addresses), then set up a scheduling policy, and then we are ready to complete the load balancing by the DNS server.

When a user initiates a request to our domain name, the DNS server automatically selects an appropriate IP address according to the preset scheduling policy, and then the user initiates a request to this IP address.

Scheduling policy

Generally, DNS providers provide scheduling strategies for us to choose, such as random allocation, polling, and assigning the server closest to the requester based on his geography.

Advantages and disadvantages analysis

The advantage of DNS load balancing is that it is easy to configure. DNS servers are responsible for scheduling the cluster of servers, so we can focus on the back-end servers to ensure their stability and throughput. And you don’t have to worry about DNS server performance, even with polling, its throughput is still excellent.

In addition, DNS load balancing is more scalable, you can resolve many IP addresses for a domain name without worrying about performance.

However, by handing over cluster scheduling to the DNS server, we can’t control the scheduler and customize the scheduling policy.

The DNS server cannot know the load of each server, so it cannot implement load balancing in the true sense. It is the same as HTTP redirection, except that all requests are equally distributed to the back-end server.

In addition, when we find a back-end server failure, even if we immediately remove the server from domain name resolution, the DNS server will have cache, the IP will still remain in DNS for a period of time, so that some users can not access the website properly. This is a fatal question! Fortunately, this problem can be solved with dynamic DNS.

Dynamic DNS

Dynamic DNS allows us to programmatically change domain name resolution in the DNS server. So that when our monitor detects that a server is down, it can immediately notify DNS to remove it.

From what has been discussed above

DNS load balancing is a crude load balancing method. It is only introduced here and not recommended.


Reverse proxy load balancing

What is reverse proxy load balancing?

The reverse proxy server is a server located in front of the actual server. All requests sent to our website first go through the reverse proxy server. The server either directly returns the results to the user according to the user’s request, or sends the request to the back-end server for processing, and then returns it to the user.

Earlier we described caching static and commonly used dynamic pages using a reverse proxy server. Next, let’s look at the more common functionality of reverse proxy servers — load balancing.

We know that all requests sent to our site first go through a reverse proxy server. The reverse proxy server can then act as a dispatcher for a cluster of servers, forwarding requests to an appropriate server based on the current back-end server load and returning the processing results to the user.

advantages

  1. Hide backend servers. In contrast to HTTP redirects, reverse proxies can hide backend servers from all browsers, ensuring control of the scheduler and improving overall cluster performance.
  2. Failover Reverse proxy can remove failed nodes more quickly than DNS load balancing. When the monitor detects a back-end server failure, it notifies the reverse proxy server and deletes it immediately.
  3. Assign tasks Properly HTTP redirection and DNS load balancing fail to implement load balancing, that is, the scheduling server cannot assign tasks based on the actual load of the back-end server. However, the reverse proxy server supports manually setting the weight of each back-end server. We can set different weights according to the configuration of the server. Different weights will lead to different probabilities of being selected by the scheduler.

disadvantages

  1. Because all requests are processed by the reverse proxy server first, when the number of requests exceeds the maximum load of the scheduling server, the throughput of the scheduling server deteriorates the overall performance of the cluster.
  2. When back-end servers cannot handle the huge throughput, the number of back-end servers needs to be increased, but it cannot be increased indefinitely because it is constrained by the maximum throughput of the scheduling server.

Viscous session

Reverse proxy servers can cause a problem. If a back-end server processes a user’s request and stores the user’s session or cache, then when the user sends a request again, there is no guarantee that the request will still be processed by the server that holds the user’s session or cache. If it is processed by another server, the previous session or cache will not be found.

Solution 1: Modify the task assignment policy of the reverse proxy server to use the user IP address as the identifier. The same user IP is processed by the same back-end server, thus avoiding the problem of sticky sessions.

Solution 2: The server ID of the request can be marked in the Cookie. When the request is submitted again, the scheduler can assign the request to the server marked in the Cookie.

 

IP – based load balancing

 

1. Implement load balancing through NAT

Operation process

  1. The client will make a request to an IP address, which is an IP addressVIP(virtual IP), which is also an address published by the scheduler.
  2. The request is reached by the scheduler, which will follow the load balancing algorithm (see 8 load balancing algorithms for details) fromRealServerSelect a low-load server from the list, and send the destination address of the request message, i.eVIPAnd port throughiptablesforNATTranslates to the real IP address of the selected server. Finally, the scheduler stores its connection in a hash table and dispatches it to the server selected last time the connection sends a request.
  3. RealServerAfter receiving the message, the response is returned to the scheduler.
  4. After receiving the packet, the scheduler changes the source IP address and source port to a virtual IP address and port, and returns the packet to the client.

The characteristics of

1. The RealServer and scheduler must reside on the same IP network. 2. The scheduler sits between the RealServer and the client and handles incoming and outgoing communications. 3.RIP is usually an internal address and is used only for communication between clusters. 4. The gateway of the RealServer must point to the scheduler. 5. Port mapping is supported. RealServer does not need a port with the scheduler.

limit

The response packets are usually large. If NAT is required every time, the scheduler becomes a bottleneck in the case of heavy traffic.

Figure captions

image.png

2. Load balancing is implemented through direct routes

describe

The network request has a characteristic that the response packet is usually much larger than the request packet, which will cause the impact of the machine load on the NAT each time it forwards, and will become a bottleneck of the request. Therefore, VS/DR can only forward requests through direct routing, and the corresponding RealServer to directly respond to the client, which can greatly improve throughput.

Operation process

  1. The client requests oneVIPThis IP address is the one published by the scheduler.
  2. After the request arrives at the scheduler, the scheduler dispatches the request according to the load algorithm and distributes it to the specifiedRealServer, the scheduler will not change the IP and port, only the MAC address will be selectedRealServerThe MAC address of,RealServerThe corresponding packet will be received.
  3. RealServerAfter receiving a packet, discover the destination IP address of the packetVIPAfter the processing is complete, the response is returned to the client through the routing table.

The characteristics of

  1. Cluster nodes,RealServerBe on the same physical network as the scheduler.
  2. RIPUsually a private network, of course, can also be a public network, easy to monitor and manage.
  3. The scheduler is only responsible for scheduling requests, and the response is answered directly by the server to the client.
  4. RealServerCannot point to the dispatcher’s gateway.
  5. Port mapping is not supported.

3. VS/TUN virtual server

describe

Since VS/DR restricts realServers and schedulers to the same physical network and therefore cannot be scattered around, VS/TUN solves this problem.

Operation process

1. The client sends a VIP request and encapsulates an IP packet to another IP packet through an IP tunnel. In this way, the data destined for one IP address can be forwarded to another IP address. 2. The scheduler selects a RealServer based on the load balancing algorithm and sends the encapsulated IP packets. 3. After the RealServer receives the packet, it decapsulates the packet and obtains the original VIP packet. After discovering that the VIP is located in the local IP tunnel, the server processes the request and sends the response packet to the client directly through the routing table.

The characteristics of

  1. RealServerAnd the scheduler must be accessible to the public network.
  2. RIPIt must be a public IP address.
  3. The scheduler only allocates and forwards requests toRealServer, the response packet is sent byRealSeverRespond directly to the client.
  4. RealServerThe gateway cannot point to the scheduler.
  5. Port mapping is not supported.
  6.  

Load balancing at the data link layer

Data link layer load balancing is actually the load balancing of network adapters. In the following applications, load balancing for network adapters should be considered:

  1. Applications running on a server can exceed 500 MB during off-peak periods, and generally exceed 1 GB during evening peak periods. Network adapters of mainstream servers are gigabit, and traffic exceeding 1 GB will obviously lead to packet loss. At this time, services cannot be stopped and network adapters cannot be replaced, so a network adapter must be added to jointly provide services. Therefore, it is necessary to bundle multiple network cards into a logical network card.
  2. High availability requirements for nics: Certain services must provide high availability at the NIC layer. Therefore, multiple nics must be bundled.

For Linux systems, the solution of the data link layer is to implement multiple network adapters bonding, known as Linux bonding, which is called Ether Channel on Cisco switches.

linux bonding

Before configuring Linux bonding, let’s talk about the following seven bond modes:

First mode: mod=0, i.e. : (balance-rr) round-robin policy

Features: Packets are transmitted in sequence (eth0 is the first packet, eth1 is the next packet… . Loop until the last transmission is completed), which provides load balancing and fault tolerance; However, we know that if the packets of a connection or session are sent from different interfaces and then pass through different links halfway, the client is likely to have the problem of disordered arrival of packets, and the disordered arrival of packets needs to be sent again, thus reducing the throughput of the network

Second mode: mod=1, that is, (active-backup) active-backup policy

Features: Only one device is active, and when one goes down the other is immediately switched from backup to master. The MAC address is externally visible. From the outside, the MAC address of the bond is unique to avoid confusion on the switch. This pattern only provides fault tolerance; It can be seen that the advantage of this algorithm is that it can provide high network connection availability, but its resource utilization is low, only one interface is in working state, and in the case of N network interfaces, the resource utilization is 1/N

Third mode: mod=2, i.e. : (balance-xor) xor policy

Features: Data packets are transmitted based on the specified HASH transmission policy. The default policy is :(source MAC address XOR destination MAC address) % slave number. Additional transport policies can be specified with the xmit_hash_policy option, which provides load balancing and fault tolerance

The fourth mode: mod=3, that is, broadcast (broadcast policy)

Features: Each data packet is transmitted on each slave interface. This mode provides fault tolerance

(802.3AD) IEEE 802.3addyNAMic Link Aggregation

Features: Create an aggregation group that shares the same rate and duplex Settings. Multiple slaves work under the same active aggregation according to the 802.3AD specification.

The slave election of outgoing traffic is based on the transmission hash policy, which can be changed from the default XOR policy to another policy with the xmit_hash_policy option. Note that not all transmission policies are 802.3AD compliant, especially considering the packet out-of-order problem mentioned in section 43.2.4 of the 802.3AD standard. Different implementations may have different adaptations.

Necessary conditions:

Condition 1: Ethtool allows you to obtain the rate and duplex Settings of each slave

Condition 2: The switch supports IEEE 802.3AD Dynamic link aggregation

Condition 3: Most switches must be configured to support 802.3AD mode

The sixth mode: mod=5, i.e. : (balance-TLb) Adaptive transmit load balancing

Features: Channel bonding does not require any special switch support. Outgoing traffic is allocated on each slave based on the current load (calculated by speed). If the receiving slave fails, the other slave takes over the MAC address of the failed slave.

Prerequisites for this mode: Ethtool allows you to obtain the rate of each slave

The seventh mode: mod=6, i.e. : (balance-alb) Adaptive load balancing

Features: This mode includes the balance-TLB mode and receive Load balancing (RLB) for IPV4 traffic, and does not require any switch support. The received load balancing is implemented through ARP negotiation. The bonding driver intercepts the ARP reply sent by the local device and changes the source hardware address to the unique hardware address of a slave in the bond. In this way, different peers use different hardware addresses for communication.

There are two common load balancers in the network:

One is through hardware, common hardware is relatively expensive NetScaler, F5, Radware and Array and other commercial load balancers, There are also open source load balancing strategies based on Linux, such as LVS, Nginx and HAproxy. In commercial load balancing, NetScaler is more efficient than F5. For the load balancer, but the commercial load balance can be based on 4 ~ 7 layer protocol, so more widely applicable so have its irreplaceability, he is a professional maintenance team to the advantages of these services are maintained, the downside is that spending is too big, so for the smaller network service temporarily haven’t need to use.

Another way of load balancing is through software: LVS, Nginx, HAproxy, etc. LVS is built on the top of the four layer protocol, while Nginx and HAproxy are built on the top of the seven layer protocol

LVS: implements high-performance, scalable, reliable, and Manageability servers using the cluster technology and Linux operating system.

The characteristics of LVS are:

1, strong load resistance, is working on the network layer 4 only for distribution, no traffic generation;

2, low configuration, which is a disadvantage is also an advantage, because there is not too much configuration of things, so it does not need too much contact, greatly reducing the probability of human error;

3. Stable operation and complete dual-system hot backup scheme;

4, no flow, to ensure that the PERFORMANCE of the EQUALIZER IO will not be affected by large flow;

5, wide application range, can do load balancing for all applications;

6. LVS needs to apply for one more IP from IDC to make Visual IP, so it needs certain network knowledge, so it has high requirements for operators.

Nginx features are:

1. Working at layer 7 of the network, you can implement some traffic diversion policies for HTTP applications, such as domain names and directory structures;

2. Nginx is less dependent on network;

3, Nginx installation and configuration is relatively simple, more convenient to test;

4, can also bear high load pressure and stable, generally can support more than 10,000 times of concurrency;

5, Nginx can detect server internal faults through the port, such as status code returned by the server to process the page, timeout, etc., and will return the error request to another node, but the shortcoming is that it does not support URL to detect;

Nginx’s asynchronous processing of requests can help lighten the load on node servers.

7. Nginx supports HTTP and Email, which makes it much smaller in scope.

8. Session persistence is not supported, Big Request header is not well supported, and only round-robin and IP-hash load balancing algorithms are supported by default. The features of HAProxy are:

1. HAProxy works on layer 7 of the network.

2, can supplement some shortcomings of Nginx such as Session persistence, Cookie boot, etc

3, support url detection backend server problem detection will be very helpful.

4. More load balancing strategies such as Dynamic Round Robin, Weighted Source Hash, Weighted URL Hash and Weighted Parameter Hash have been implemented

5. In terms of efficiency, HAProxy has better load balancing speed than Nginx.

6. HAProxy can perform load balancing on Mysql and detect and load balancing on back-end DB nodes.

The current trend of the development of websites is to use different technologies according to different stages as the size of websites increases:

The first stage: use Nginx or HAProxy to carry out single-point load balancing. In this stage, the server scale just broke away from the single-server and single-database mode, requiring certain load balancing. However, the scale is still small, and there is no professional maintenance team for maintenance, and there is no need to carry out large-scale website deployment. Using Nginx or HAproxy is the first choice. These things are quick to use, easy to configure, and use HTTP over layer 7. This is the first choice

Stage 2: With the further expansion of network services, a single point of Nginx is no longer enough, so using LVS or commercial F5 is the first choice. Nginx will be used as the node of LVS or F5. The specific choice of LVS or F5 is based on the size of the company, talent and financial capacity. But in general, the talent involved can’t keep up with the growth of the business at this stage, so buying commercial load balancing has become a necessary step.

The third stage: At this time, network service has become the mainstream product. At this time, with the further expansion of the company’s popularity, the ability and number of related talents will also improve. At this time, open source LVS has become the first choice in terms of developing customized products suitable for its own and reducing costs. The ideal state is F5/LVS< — >Haproxy< — >Squid/Varnish< — >AppServer