In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces you what is the core principle of micro-service architecture, the content is very detailed, interested friends can refer to, hope to be helpful to you.
The concept of micro-service was first put forward in 2012. With the promotion of Martin Fowler, micro-service has been greatly developed since 2014. Today we use a set of hand drawings to tease out the core architecture of microservices.
What is a microservice?
Martin, the father of microservices Microservices. Fowler, a general overview of microservices is as follows:
At present, there is no unified and standard definition (While there is no precise definition of this architectural style) for the micro-services industry.
But generally speaking, the micro-service architecture is an architectural pattern or an architectural style, which advocates dividing a single application into a group of small services, each running in its own independent process. Services coordinate and cooperate with each other to provide users with the ultimate value.
Services use a lightweight communication mechanism to communicate with each other (usually RESTful API based on HTTP). Each service is built around a specific business and can be independently deployed to a production environment, class production environment, and so on.
In addition, a unified and centralized service management mechanism should be avoided as far as possible. for a specific service, we should choose the appropriate language and tools to build it according to the business context. there can be a very lightweight centralized management to coordinate these services. Services can be written in different languages, or different data stores can be used.
According to Martin. Fowler's description, I summed up the following points:
① Mini Service
Small service, there are no specific standards or specifications, but it must be small in the overall specification.
② process independent
Each set of services runs independently, maybe my service runs on the Tomcat container and the other service runs on Jetty. The entire service can be continuously expanded horizontally through the process.
③ communication
In the past, protocols are very heavy, like ESB, like SOAP, light communication, which means that compared to the past, smarter and lighter services call each other, the so-called smart endpoints and dumb pipes.
These Endpoint are decoupled, and completing a business communication call to string up these Micro Service is like a series of command services through pipes in a Linux system.
In the past business, we usually consider a variety of dependencies and the problems caused by system coupling. Micro-services allow developers to focus more on the logical development of the business.
④ deployment
Not only should the business be independent, but the deployment should also be independent. However, this also means that the traditional development process will change to a certain extent, and the suitability of development should also have certain operation and maintenance responsibilities.
⑤ management
Traditional enterprise-level SOA services are often very large, not easy to manage, high coupling, and high team development costs.
Micro-service allows teams to choose their own technology implementation, and different Service can choose different technology stacks according to their own needs to implement their business logic.
Advantages and disadvantages of micro-service
Why use microservices? Because it's fun? No. Here are the more comprehensive advantages I found on the Internet:
The advantage is that each service is sufficiently cohesive and small enough that the code is easy to understand so that it can focus on a specified business function or business requirement.
Development is simple and efficient, and a service may be dedicated to doing only one thing.
Microservices can be developed separately by a small team of two to five developers.
Microservices are loosely coupled and functionally meaningful, and are independent in either the development phase or the deployment phase.
Microservices can be developed in different languages.
Easy to integrate with third parties, microservices allow easy and flexible ways to integrate automatic deployment through continuous integration tools such as Jenkins,Hudson,bamboo.
Microservices are easy for a developer to understand, modify, and maintain, so that small teams can pay more attention to their work. There is no need for cooperation to realize value. Microservices allow you to take advantage of the latest technologies.
Microservices are just code for business logic and will not be mixed with HTML,CSS or other interface components.
Each microservice has its own storage capacity, can have its own database, can also have a unified database.
Generally speaking, the advantage of micro-service is that in the face of large systems, it can effectively reduce the complexity and make the logic of the service architecture clearer.
But this will also bring a lot of problems, such as data consistency in distributed environment, complexity of testing, complexity of operation and maintenance. Our company has used distributed locks for 6 years, which is very powerful. I recommend you to take a look at it.
What organization is suitable for using microservices?
Micro-service has a variety of advantages and disadvantages, so what organization is suitable to use micro-service?
① Murphy's Law (Design system) and Conway's Law (system Division) Conway's Law is a micro-service concept that was put forward more than 50 years ago. The most famous sentence in Conway's article is:
Organizations which design systems are constrained to produce designs which are copies of the communication structures of these organizations.
-Melvin Conway (1967)
The design of the organization of the design system is equivalent to the communication structure within and between organizations.
Take a look at the picture below, and then think about Apple's products, Microsoft's product design, you can vividly understand this sentence.
Those who are interested can study it!
② architecture evolution
Architecture is constantly evolving, and so is micro-service. when the scale of major technology companies is large to a certain extent, it completely needs to evolve into a technical architecture system for further management. Taobao 10 million concurrency, 14 architecture evolution, recommend you to take a look.
Traditional teams are all process-oriented, looking for planning after thinking about the product, looking for development after planning, and then looking for it step by step.
We do the technology for the product, and once something goes wrong with the process, it can be very time-consuming to look back for the problem.
Using the micro-service architecture, the team organization needs to be transformed into a cross-functional team, that is, each team has product experts, planning experts, development experts, and operation and maintenance experts, who use API to publish their functions, while the platform uses their functions to publish products. Recommend an interface API design artifact! Recommended.
Micro-service technology architecture
Next, I would like to share the micro-service technology architecture used by most companies:
Service discovery
There are three types of mainstream service discovery:
First, after the developer has developed the program, they will find a domain name for operation and maintenance, and if the service is provided, we can find our corresponding service through DNS.
The disadvantage is that because the service has no load balancing function, there may be considerable performance problems for the load balancing service.
The second is the common practice at present. You can refer to the Zuul gateway. Each service is registered with the registry through the built-in function of the server. Service consumers constantly poll the registry to find the corresponding service and use the built-in load balancer to invoke the service. Why do microservices have to have gateways? I recommend you to take a look.
The disadvantage is that it is not very good for multilingual environments, and you need to develop service discovery and load balancing functions separately for consumers' clients. Of course, this method is usually used on Spring Cloud.
The third is to put the client and the load balancer on the same host, not in the same process.
[] compared with the first and second method, this method improves their shortcomings, but it will greatly increase the cost of operation and maintenance.
Gateway
What is the gateway for microservices? We can get in touch with life and think about it. Every big company will have its own building area, and there are many doormen in this building area. If outsiders enter the company, they will say hello to the doorman before they can enter.
It is not difficult to understand the meaning of gateways by connecting the reality of life to microservices:
The purpose of the gateway is as follows:
Reverse routing: in many cases, companies do not want outsiders to see the inside of our company, so they need gateways for reverse routing. Convert an external request into an internal concrete service call.
Security authentication: there will be many malicious visits in the network, such as crawlers, such as hacker attacks, gateways to maintain security functions.
Current-limiting circuit breaker: when many requests for services are overwhelmed, our services will be automatically shut down, resulting in unavailability of services. Current-limiting fuse can effectively avoid this kind of problem.
Log monitoring: all external requests pass through the gateway so that we can use the gateway to record log information.
Grayscale release, blue and green deployment. It refers to a release way that can make a smooth transition. On it, it can be carried out as A testing B testing. That is, let some users continue to use product feature A, and some users begin to use product feature B. if users have no objection to B, then gradually expand the scope and migrate all users to B.
Open source gateway Zuul architecture:
The core of the Zuul gateway is actually a Servlet, and all requests are sent to ZuulFilter Runner via Zuul Servlet and then distributed to the three filters.
Let's start with the left half of the architecture diagram, which are the pre-route filter, route filter and post-route filter implemented by Groovy.
General requests are first processed by a pre-routing filter, and the general custom Java encapsulation logic is also implemented here.
The route filter is to find the corresponding micro-service to invoke. When the call is finished, the response will go through the post route filter, through which we can encapsulate the log audit processing.
It can be said that the biggest feature of Zuul gateway is its three-layer filter. Is a custom filter loading mechanism designed by the Zuul gateway.
There will be a producer-consumer model inside the gateway, and the filter script will be automatically published to the Zuul gateway to read and load.
Configuration center
In the past, developers put configuration files in development files, which had a lot of hidden dangers. For example, the configuration specification is different and the configuration personnel cannot be traced back. A comprehensive comparison of the micro-service configuration center, which is more powerful? This article is recommended for everyone to read.
Once the need for large-scale configuration changes, the changes will take a long time, unable to trace the configuration personnel, thus affecting the entire product, the consequences are we can not afford.
So there is the configuration center of this! Now the open source center has Baidu configuration center Disconf,Spring Cloud Config,Apollo.
Today, we will focus on the configuration center with good application quality, Ctrip's open source Apollo:
The scale of the configuration center of Apollo is relatively large, and the local application will have a responsive configuration center client, which can periodically synchronize the configuration in the configuration center. If the configuration center is idle, the cache will be used for configuration. Follow Wechat official account: Java technology stack, reply: architecture in the background, you can get N pieces of the latest architecture information that I have sorted out.
Communication mode
With regard to communication methods, there are generally two kinds of remote calls in the market. I have sorted out a table:
Monitoring and early warning
Monitoring and early warning is very important for micro-services, and a reliable monitoring and early warning system is very important for the operation of micro-services.
General monitoring is divided into the following levels:
From the infrastructure to the client, there are layers of monitoring, omni-directional, multi-angle, every level is very important.
In general, microservices can be divided into five monitoring points:
Log monitoring
Metrics monitoring
Health examination
Call chain check
Alarm system
① monitoring architecture
The following figure is a monitoring architecture diagram for most companies. Each service has an Agent,Agent that collects key information and passes it to some MQ for decoupling.
At the same time, the log is passed into ELK, and Metrics is passed into the InfluxDB time series library. Like Nagios, you can periodically initiate an information check microservice to Agent. Follow Wechat official account: Java technology stack, reply: architecture in the background, you can get N pieces of the latest architecture information that I have sorted out.
② call chain monitoring APM
Many companies have call chain monitoring. For example, Ali has Hawkeye monitoring, review Cat, and most call chain monitoring (yes, I mean Zipkin) architecture goes like this:
When the request enters the Web container, the Tracer is created to connect to the Spans (simulating the latent latency of distributed work, and the module also contains toolkits for passing tracking context information between system networks, such as through HTTP Headers).
Spans has a context that contains the Tracer identifier and places it in the correct place in the tree that represents the distributed operation.
When we put the various Span in the diagram to the back end, our service invocation chain will dynamically generate the call chain.
Here are some comparisons of call chain monitoring that are widely used in the market:
Fuse, isolation, current limit, downgrade
In the face of huge sudden traffic, large companies usually use a series of circuit breakers (the system automatically shuts down services to prevent problems to be maximized), isolation (isolating services and services). Prevent one service from failing and other services cannot be accessed), flow restriction (allowing a certain number of users to access per unit time), degradation (when the overall load of the entire microservice architecture exceeds the preset upper limit threshold or the upcoming traffic is expected to exceed the preset threshold, in order to ensure the normal operation of important or basic services We can delay or suspend the use of some unimportant or urgent services or tasks.
The following describes the running process of Hystrix:
If Hystrix stops development, where will Spring Cloud go?
When each micro service is called, it uses the Command mode of Hystrix (the one in the upper left corner of the image above), and then uses Command synchronous, either responsive or asynchronous to determine whether the circuit is broken (looking from left to right along the diagram), and downgrade Fallback if the circuit is broken.
If the line is closed, but the thread resources are gone and the queue is full, take the flow restriction measure (see step 5 of the figure).
If you are done and the execution is successful, go to the run () method to get the Response, but if something goes wrong, continue to downgrade the Fallback.
At the same time, at the top of the picture, there is a suffix with Health, which is a component that calculates whether the entire link is healthy, and every step is recorded by it.
Container and Service orchestration engine
From physical machine to virtual machine, from virtual machine to container, from physical cluster to OpenStack,OpenStack to Kubernetes; technology, our cognition has not been refreshed.
Let's start with the container, which is first of all a relatively independent running environment, which is a bit similar to a virtual machine, but not as thorough as a virtual machine.
The virtual machine packages the virtual hardware, kernel (that is, operating system) and user space in the new virtual machine, and the virtual machine can use the hypervisor to run on the physical device.
Virtual machines rely on Hypervisor, which is usually installed on "bare metal" system hardware, which leads Hypervisor to be considered an operating system in some ways.
Once the Hypervisor installation is complete, virtual machine instances can be allocated from the computing resources available on the system, and each virtual machine can get a unique operating system and load (applications).
In short, virtual machines need to virtualize a physical environment, then build a complete operating system, build a layer of Runtime, and then run applications.
For a container environment, there is no need to install the host operating system, but the container layer (such as LXC or Libcontainer) is installed directly on top of the host operating system (usually a Linux variant).
After the container layer is installed, container instances can be allocated from the computing resources available to the system, and enterprise applications can be deployed in containers.
However, each containerized application shares the same operating system (a single host operating system). The container can be regarded as a virtual machine installed with a specific set of applications, which directly uses the kernel of the host. The abstraction layer is less, lighter and faster than the virtual machine.
The container has more efficient use of resources than virtual machines because it does not require a separate operating system for each application-smaller instances and faster creation and migration. This means that a single operating system can host more containers than a virtual machine.
Cloud providers are very keen on container technology because more container instances can be deployed in the same hardware device.
In addition, containers are easy to migrate, but can only be migrated to other servers with compatible operating system kernels, which limits migration options.
Because containers do not package kernel or virtual hardware like virtual machines, each container has its own isolated user space, allowing multiple containers to run on the same host system.
We can see that all operating system-level architectures can be shared across containers, and the only ones that need to be built independently are binaries and libraries.
Because of this, containers have excellent lightweight features. Our most commonly used container is Docker.
① container choreography
In the past, virtual machines could manage virtualization through the cloud platform OpenStack. How to manage containers in the container era? It depends on the container orchestration engine.
Apache Mesos:Mesos is based on Master,Slave architecture, the framework determines how to use resources, Master is responsible for managing the machine, Slave will regularly report the machine situation to Master,Master and then give the information to the framework. Master is highly available because of the existence of ZK and Leader.
The following is the architecture diagram:
The design concept and function of Kubernetes is actually a hierarchical architecture similar to Linux. First, within each Kubernetes node, kubelet manages the global pod, while each pod carries one or more containers, and kube-proxy is responsible for network proxy and load balancing.
Outside the Kubernetes node, there is the corresponding control and management server, which is responsible for the unified management of the scheduling, distribution and operation of each node.
So much for sharing what is the core principle of micro-service architecture. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.