Dry full! Load balancing distributed systems | Architecture dry

Personal blog navigation page (click on the right link to open a personal blog): Daniel take you on technology stack 

First, what is load balancing?

What is load balancing?

I remember the first contact with Nginx in the lab, when deployed in the server site requires Nginx. Nginx is a service component for a reverse proxy, load balancing and HTTP caching. So here is what load balancing is?

Load balancing (LB, Load Balance), it is a technology solutions. For allocating a plurality of resources (typically the server) load, optimize the use of resources, to avoid overload.

file

Resources, equivalent to each service instance unit to perform operations, load balancing is to share large amounts of data processing operations to execute multiple operating units, to solve the problem of a large flow of Internet distributed systems, high concurrency and high availability. What is the availability of it?

Second, what is the availability?

First, understand what is highly available?

This is the CAP theorem is the basis of three indicators distributed systems, distributed systems also:

  1. Consistency (Consistency)
  2. Availability (availability)
  3. Partition tolerance (partitions fault tolerance)

What is that high availability (High Availability) that? Availability, referred to as the HA, is a system feature or indicators, generally it refers to provide a certain service run time performance, higher than the average normal period. On the contrary, the elimination of the system service time is unavailable.

Measurement system meets the high availability, is that when a server goes down or when more than one of the system as a whole and normal service is still available.

For example, some well-known sites to ensure the availability of four or more of 9, that is, the availability of over 99.99%. That 0.01% is the percentage of so-called downtime. For example, the electricity supplier website to praise, service is not available will result in loss of money and business users. Well the same time, system downtime and service is not available will increase the availability of compensation basis.

file

Under such a single service, a plurality of service instances with a single load balancing, instead of a single instance of service orders, i.e., the use of redundant manner to increase reliability.

All in all, load balancing (Load Balance) is one of the factors in the distributed system architecture design must be considered. Usually by load balancing, redundancy with a service instance, a distributed problem-solving system of high flow, high concurrency and high availability. Load balancing core key: whether the distribution is uniform.

Third, the common load balancing case

file

Scenario 1: micro-service architecture, the gateway routing to a specific service instance Hello:

  • Two identical service instances hello service, a port 8000, another port 8082
  • LB Kong through load balancing feature that allows uniform distribution of the requested service instances hello to two
  • Many Kong load balancing algorithm strategy: default weighted-round-robin algorithm, as well as consumer: consumer id as the hash algorithm input values, etc.

file

Scenario 2: micro-services architecture, A service call cluster B services. Ribbon by the client load balancing components:

  • Advanced load balancing strategy algorithm is not the easiest choice is random and round robin

Fourth, the Internet distributed system solutions

file

Common Internet distributed system architecture has several layers, generally as follows:

  • Client layer: for example, the user's browser, APP end
  • Reverse proxy layer: F5 or the like technology selection Nignx
  • Web layer: front and rear ends separated scenario, Web terminal can NodeJS, RN, Vue
  • Business Services layer: with Java, Go, general Internet companies, technical program selection is SC or services of Spring Boot + Dubbo
  • Data storage layer: DB Selection MySQL, Cache Selection Redis, search Selection ES, etc.

A request from layer 1 to layer 4, the layers of access requires load balancing. I.e., each call upstream traffic downstream side of the plurality of time required uniform call. In this way the whole system point of view, it is more load balancing

Tier 1: Client Layer -> Load balancing reverse proxy layer

Client Layer -> Load balancing reverse proxy layer of how to achieve it?

The answer is: DNS polling. DNS by A (Address, pointing to the return address of the DNS IP) a plurality of IP addresses. For example, here to visit the ip1 bysocket.com DNS configuration and ip2. Reverse proxy layer to availability, there will be at least two A record. Such redundant nginx ip two corresponding service instances, prevent single points of failure.

Every request bysocket.com domain by polling DNS, returns the corresponding ip address, each service instance corresponding to the reverse proxy ip layer, i.e. nginx external network ip. This can be done for each request for a reverse proxy distribution layer obtained is equalized example.

Tier 2: Reverse Proxy Layer -> Load Balancing Web layer

Reverse Proxy Layer -> Load Balancing Web tier of how to achieve it?

Load balancing module is processed by the reverse proxy layer. There are several balancing methods such as nginx:

  1. Polling request. Request chronologically assigned one by one to the web service layer, and then again and again. If the web service layer is down, automatically remove
upstream web-server {
    server ip3;
    server ip4;
}
  1. ip hash. In accordance with the hash value of ip, is determined corresponding route to the web layer. Ip as long as the user is uniform, then the request to the Web layer is uniform. There is a benefit that the same ip requests will be distributed to the same web service layer. Fixed so that each user access a web service layer, can solve the session problem.
upstream web-server {
    ip_hash;
    server ip3;
    server ip4;
}
  1. weight weight, fair, url_hash etc.

Tier 3: Web Layer -> Load Balancing Business Services layer

Web Tier -> How to Load Balancing business services layer to achieve it?

For example, Dubbo is a service management program, including the service registration, service degradation, access control, dynamically configurable routing rules, weight adjustment, load balancing. One feature is the intelligent load balancing: Built-in a variety of load balancing strategy, IntelliSense health of downstream node, significantly reduce call latency, improve system throughput.

In order to avoid single point of failure and support services lateral expansion, a service often deploy multiple instances, namely Dubbo cluster deployment. A plurality of service instances will be a service provider, then the random load balancing policy configuration Provider in 20 randomly selected one of the call to the Null seventh Provider. LoadBalance components from the provider address list, use a balanced strategy, choose a provider selected call, if the call fails, then select another call.

Dubbo built four load balancing strategy:

  • RandomLoadBalance: random load balancing. A random choice. Dubbo is the default load balancing strategy.
  • RoundRobinLoadBalance: Polling load balancing. Select a poll.
  • LeastActiveLoadBalance: Minimum number of active calls, the same random number is active. Number of active call count refers to the difference between before and after. So that less slow Provider receives the request, the greater will be the difference between before and after the call because the slower Provider count.
  • ConsistentHashLoadBalance: consistent hashing load balancing. Request the same parameters always falls on the same machine.

Also, because the business needs, you can implement your own load balancing strategy

Layer 4: Business Services Layer -> Load Balancing data storage layer

Load balancing data storage layer, typically achieved by DBProxy. For example, MySQL sub-library sub-table.

When a single database or a single table access is too large, too large an amount of data need to be split vertically and horizontally split two dimensions. For example, the level of segmentation rules:

  • Range, time
  • modulo hash, the shop ID or the like according to the order

But with this load following questions will need to be addressed:

  • Distributed Transaction
  • Cross-database join, etc.

Status sub-library sub-table product solutions are many: Dangdang sharding-jdbc, Ali Cobar, etc.

V. Summary

External view, load balancing is a whole system or software. It seems the inner layers of the upstream and downstream calls. As long as there is a call, we need to consider this factor load balancing. So load balancing (Load Balance) is one of the factors in the distributed system architecture design must be considered. Consider how to make the downstream mainly received request are evenly distributed:

  • Tier 1: Client Layer -> Load balancing reverse proxy layer. Polling by DNS
  • Tier 2: Reverse Proxy Layer -> Load Balancing Web layer. By Nginx load balancing module
  • Tier 3: Web Layer -> Load Balancing Business Services layer. By load balancing service modules governance framework
  • Layer 4: Business Services Layer -> Load Balancing data storage layer. By the horizontal distribution of the data, even data, and the request will theoretically uniform. Similarly by such buyer ID fragment

Attached Java / C / C ++ / machine learning / Algorithms and Data Structures / front-end / Android / Python / programmer reading / single books books Daquan:

(Click on the right to open there in the dry personal blog): Technical dry Flowering
===== >> ① [Java Daniel take you on the road to advanced] << ====
===== >> ② [+ acm algorithm data structure Daniel take you on the road to advanced] << ===
===== >> ③ [database Daniel take you on the road to advanced] << == ===
===== >> ④ [Daniel Web front-end to take you on the road to advanced] << ====
===== >> ⑤ [machine learning python and Daniel take you entry to the Advanced Road] << ====
===== >> ⑥ [architect Daniel take you on the road to advanced] << =====
===== >> ⑦ [C ++ Daniel advanced to take you on the road] << ====
===== >> ⑧ [ios Daniel take you on the road to advanced] << ====
=====> > ⑨ [Web security Daniel take you on the road to advanced] << =====
===== >> ⑩ [Linux operating system and Daniel take you on the road to advanced] << = ====

There is no unearned fruits, hope you young friends, friends want to learn techniques, overcoming all obstacles in the way of the road determined to tie into technology, understand the book, and then knock on the code, understand the principle, and go practice, will It will bring you life, your job, your future a dream.

Published 47 original articles · won praise 0 · Views 258

Guess you like

Origin blog.csdn.net/weixin_41663412/article/details/104898968