A comprehensive analysis of "distributed basic concepts" allows you to understand distributed systems in seconds! 【one】

foreword

Learn these technologies in the project, deepen their use and deep understanding. The following summary comes from the case information of the Guli Mall project

1. What is microservice?

       The microservice architectural style is like developing a single application as a set of small services, each of which runs in its own process and communicates using a lightweight mechanism , usually an HTTP API. These services are built around business capabilities and are deployed independently through fully automated deployment mechanisms. These services are written in different programming languages, as well as different data storage technologies, and keep a minimal centralized management.

In short: Reject large monolithic applications, micro-splitter services based on business boundaries, and deploy and run each service independently

insert image description here

2. Cluster, distributed, node

Cluster is a physical form, and distributed is a way of working.

As long as it is a bunch of machines, it can be called a cluster. No one knows whether they work together or not;

"Distributed System Principles and Paradigms" defines: "A distributed system is a collection of independent computers that appear to users as a single related system." A
distributed system is a software system built on a network .

Distributed refers to the distribution of different businesses in different places .

Clustering refers to bringing together several servers to achieve the same business .

For example: Jingdong is a distributed system, many businesses run on different machines, and all businesses form a large business cluster. For each small business, such as user systems, one server is not enough when the access pressure is high. We should deploy the user system to multiple servers, that is, each business system can also be clustered;

Each node in the distributed system can be used as a cluster. And the cluster is not necessarily distributed.

Node: A server in a cluster

3. Remote call

In a distributed system, each service may be located on different hosts, but the services inevitably need to call each other, which we call remote calls

Use HTTP+JSON to complete remote calls in Spring Cloud

insert image description here

4. Load balancing

Ten million requests came, and all the pressure was given to one server. That's not a very dangerous thing, it's better to set up a few more servers to share a wave of pressure.

       In a distributed system, A service needs to call B service, and B service exists in multiple machines, and A can call any server to complete the function.
       In order to keep each server from being too busy or too idle, we can call each server in a load-balanced manner to improve the robustness of the website.

Common load balancing algorithm:
round robin : select the first backend server in the healthy pool for the first request, and then select it sequentially until the last one, and then loop.

Minimum connection : Prioritize the back-end server with the least number of connections, that is, the least pressure. This method can be considered in the case of long sessions.

Hash : Select the server to be forwarded according to the hash (hash) of the IP of the request source. This approach can guarantee to a certain extent that specific users can connect to the same server. Consider this approach if your application needs to handle state and requires the user to be able to connect to the same server as before.

insert image description here

5. Service Registration/Discovery & Registration Center

This is also relatively easy to understand: how different services perceive each other's existence, and each service registers the services it provides to the registration center. Just like renting a house, the landlord first submits the relevant information about his house to the intermediary, and then you can find the house through the intermediary.

       Service A calls service B. Service A does not know which servers B service is currently on, which ones are normal, and which services have been offline. To solve this problem, the registration center can be introduced;

insert image description here
If some services go offline, the rest of us can perceive the status of other services in real time, so as to avoid calling unavailable services

6. Configuration Center

       Each service ends up with a lot of configuration, and each service may be deployed on multiple machines. We often need to change the configuration, we can let each service obtain its own configuration in the configuration center.

The configuration center is used to centrally manage the configuration information of microservices

       For example, configuration of database connection, connection configuration of redis, related configuration of nginx, configuration of service registration and discovery, etc. Wouldn’t it be troublesome to modify the code every time? By using the configuration center to manage the unified configuration, you can easily complete these configurations in the form of a visual operation interface.

insert image description here

7. Service circuit breaker & service downgrade

When the remote service you call is down, you still go to access this service, that's not nonsense. After waiting for a long time, there was no response, and finally an error was reported. Mentality burst, use the service fuse mechanism, when the called service dies, call it, return a default value directly. Tell him that my service is temporarily unavailable. Service degradation, when a service is heavily accessed

In the microservice architecture, microservices communicate through the network and there is interdependence. When one of the services is unavailable, it may cause an avalanche effect. To prevent such a situation, fault-tolerant mechanisms must be in place to protect the service.

insert image description here

  • 1. Service fuse
    • a. Set the timeout of the service. When the called service often fails to reach a certain threshold, we can enable the circuit breaker protection mechanism, and subsequent requests will no longer call this service. The local directly returns the default data
  • 2. Service downgrade
    • a. During the operation and maintenance period, when the system is at its peak and the system resources are tight, we can degrade the non-core business. Downgrade: Some services do not handle, or simply handle [throw exception, return NULL, use Mock data, call Fallback to process logic].

8. API Gateway

In the microservice architecture, API Gateway is an important component of the overall architecture. It abstracts the public functions required in microservices , and at the same time provides client load balancing, automatic service fuse, gray release, unified authentication, and current limiting and flow control. , log statistics and other rich functions help us solve many API management problems

insert image description here

Guess you like

Origin blog.csdn.net/weixin_43304253/article/details/130340340
Recommended