SpringCloud (1)-A preliminary study of microservices

1. What is a microservice?

Here is a quote from Zhihu Lao Liu's picture and related understanding      https://www.zhihu.com/question/65502802/answer/802678798

Online supermarket:

Introduced WeChat and APP to further expand

 

Upgrade again, take out the redundant modules and independently become a system

 

Careful friends can find that the bottleneck of the system at this time is the database, so it is upgraded again, and the database is split and added to the message queue mechanism. The frequency of access to commodity services and promotional services is high, so the cache mechanism is added.

The role of mq

Service monitoring:

Although the microservice architecture seems logically perfect, there are also problems:

  • It is very difficult to locate the point of failure
  •  A server failure may cause other servers to hang up together
  • Heavy deployment and management workload
  • Test inconvenience

So in order to solve the problem: 1. Reduce the probability of failure 2. Reduce the impact of the failure, so the monitoring system came into being. The system realization idea is to let each component report its current state, and then use an indicator collector component to obtain and save regularly The status of each component can be specified to query the current status of a component, and finally the data is displayed in the UI. Here is an example of goods and services

 Link tracking:

A user's request often involves multiple internal service calls. In order to locate the problem conveniently, it is necessary to be able to record how many service calls are generated inside the microservice when each user requests, and the call relationship. This is called link tracking. Let's use a link tracking example in the Istio document to see the effect:

As you can see from the figure, this is a request from a user to visit the productpage page. During the request process, the productpage service sequentially calls the interfaces of the details and reviews services. The reviews service calls the ratings interface during the response process. The record of the entire link tracking is a tree and an implementation scheme

 

 Log monitoring:

 When the number of visits increases, or the size of the server increases, the size of the log files will swell to be difficult to access with a text editor, and worse, they are scattered on multiple servers. To troubleshoot a problem, you need to log in to each server to obtain the log files, and search for the desired log information one by one (and it is very slow to open and search). Therefore, when the application scale becomes larger, we need a " search engine " for logs . In order to be able to accurately find the desired log. Common log analysis components: ELK (Elasticsearch, Logstash, Kibana)

  • Elasticsearch: search engine, log storage
  • Logstash: Log collector, which receives log input, performs some preprocessing on the log, and then outputs it to Elasticsearch
  • Kibana: UI component, find data through Elasticsearch API and display it to users

EFK (Elasticsearch, Filbeat/Fluent, Kibana): Use one of Fibeat or Fluent, both have similar functions

  • Filbeat: Log collection tool, an optimized version of Logstash
  • Fluent: Log collection tool

Gateway routing: 

 A large number of services and a large number of interfaces make the entire call relationship messy. Often in the development process, when I write, I suddenly can't remember which service should be called for a certain data. Or it was written crookedly, a service that should not be called was called, and a read-only function originally modified the data... In order to deal with these situations, the invocation of microservices needs a gatekeeper, that is, the gateway, which is authorized every time it is called check.

 Fuse:

When a service stops responding for various reasons, the caller usually waits for a period of time, then times out or receives an error return. If the call link is relatively long, it may cause requests to accumulate, and the entire link takes up a lot of resources and has been waiting for downstream response. Therefore, when a service fails to be accessed multiple times, it should be fuse, mark that the service has stopped working, and return an error directly. The connection will not be re-established until the service returns to normal.

Service degradation:

 When the downstream service stops working, if the service is not the core business, the upstream service should be downgraded to ensure that the core business is not interrupted. For example, the online supermarket ordering interface has a function to collect orders for recommended products. When the recommendation module is hung up, the ordering function cannot be hung up at the same time. You only need to temporarily turn off the recommendation function.

Limiting: 

 After a service hangs up, upstream services or users generally habitually retry access. As a result, once the service returns to normal, it is likely to hang up immediately because of excessive network traffic, repeating sit-ups in the coffin. Therefore, the service needs to be able to protect itself-current limit. There are many current limiting strategies, the simplest is for example, when there are too many requests per unit of time, discarding excess requests. In addition, you can also consider partition current limit. Only reject requests from services that generate a large number of requests. For example, both commodity services and order services require access to promotional services. Commodity services initiate a large number of requests due to code issues. Promotional services only restrict requests from commodity services. Requests from order services are normally responded to.

 

New content supplement, quoted from: https://www.jianshu.com/p/7293b148028f

What kind of service is considered a microservice?

  • Single responsibility. A microservice should have a single responsibility. This is the embodiment of "micro". A microservice solves a business problem (note that it is a business problem rather than an interface).
  • Service-oriented. Encapsulate your own business capabilities and provide external services. This is the core idea of ​​inheriting SOA. A microservice itself may also use the capabilities of other microservices.

At present, the main microservice frameworks used by domestic enterprises are Spring Cloud and Dubbo (or DubboX), but the suspension of Dubbo in those two years has severely affected developers’ confidence in it, and Spring Cloud has gradually become the mainstream

Service registration and discovery :

After applying microservices, the first problem encountered is service discovery. How can one microservice discover other microservices? The simplest way is to configure the addresses of other microservices in each microservice, but this is obviously unrealistic when there are a large number of microservices. Therefore, one of the most important components in the microservice architecture needs to be used: the service registry , all services are registered to the service registry, and the list of currently available services can also be obtained from the service registry:

Optional components for service registration and discovery: Zookeeper, Eureka, Consul, etc. 

Configuration service:

When the number of services exceeds a certain level, if you need to maintain the configuration files of each service separately, the operation and maintenance personnel is estimated to cry, then you need to have a configuration center to manage the configuration of the service.

3.SpringCloud

 

Guess you like

Origin blog.csdn.net/hzkcsdnmm/article/details/107100968