当前位置:网站首页>Understand microservices bit by bit
Understand microservices bit by bit
2022-07-26 08:06:00 【JavaMonsterr】
History of architecture evolution
As the number of users increases , Our project is in a Tomcat Containers 、 One MySQL It's hard on the database , Users complain about the slow response speed , We observe on the server CPU Share soared , Insufficient available memory . This centralized structure is shown in the following illustration , It can also be called “ Single machine or single structure (Monolith)”.

It's certainly a good thing that the number of users has increased , For our technicians, the challenge is even greater . First of all, we can think of some simple and direct methods , Upgrading bandwidth 、 Upgrade the server hardware configuration —— Pretty good , In addition to these horizontal methods , There is also the method of vertical dimension , And this is deeply combined with software , It is not as simple as simply modifying the hard configuration .
In the beginning Web The server 、 database 、 File resources run on the same machine , The processing capacity of a server is limited , First separate them :Web The server is independent of one machine 、 The database is independent of one machine 、 File storage is independent of a machine —— obviously , Files of static resources, such as pictures 、 Video and so on do not need dynamic processing , So using Apache or Nginx that will do , need not Tomcat, Or deploy in Alibaba cloud OSS Specifically optimize the storage of files , Even join the network optimization CDN Mechanism .
This structure can be called distributed (Distributed) Structure is shown in figure 2 Shown , Of course, the current practice is roughly divided according to the software form .

meanwhile ,Web The program adds various cache Services , for example JSP Dynamic page static , That is also a caching strategy , Of course, there are also special ones for caching Redis or Memcache Service for .
Of course, the database is also related to Web Server separation . If the performance bottleneck is found in the database , Take master-slave database (Master/Slave)、 Strategies of read-write separation and database and table segmentation . At the same time, we should continue to optimize SQL, Join indexing and other work . At this stage, the specific architecture shown in the illustration is finally formed .

After the number of users reaches a certain order of magnitude , It is found that the above optimization methods are ineffective , What to do ? The above is a machine doing one thing , A machine alone cannot do it , Many machines are needed to support it , So it's still a pile of machines , But the strategy is obviously different . This way we call it “ Cluster structure (Cluster)”, As shown in the illustration .

Services originally run on a single machine , Whether it's Web Server or database server , Take it as a node (Node) Make multiple copies , It forms a cluster , Is multiple instances of a component . For example, at the same time 100 Please come here , The backend is ready for 10 platform Web The server , Then distribute it equally to each set 10 A request to process . It can be seen that there is a key role in scheduling how these nodes respond to requests , be called “ Load balancing server ”, All requests from the user are given to it first , Then implement the distribution according to the load . Through a certain algorithm , Let idle nodes ( Low load ) Priority response , The faulty node is not involved .
The benefits of more machines go beyond the improvement of performance , It also makes disaster tolerance possible , When a machine hangs, it hangs , The cluster machine allows some machines to hang up and the whole system is still available .
Please experience distributed ( As illustrated in the illustration 7.2) With clusters ( As illustrated in the illustration 7.4) Subtle differences , The reason why distributed tasks are distinguished A、B、C…… Represents different businesses that have been split , For example, an order business in the mall can be divided into order initialization business 、 Payment business 、 Financial business 、 Logistics business ; There is no distinction between the tasks of the cluster A、B、C…… Yes means that the task is an overall business , Not split and isolated from each other , Replication is performed on multiple servers . in other words , The task under the cluster is still a single machine application , It includes multiple business capabilities , And no communication with other nodes , The task is completed in the process of a single node from beginning to end .
Clustering and distribution do not conflict , In practice, they are often used together .
When the business grows to a certain extent , It is found that the above optimization methods are ineffective , What to do ? Although the advantage of the cluster structure is that the system horizontal expansion is very easy , But it has to be said that the cost of stacking machines is very high . Besides, this problem is not linear , For example, the second kill promotion in the e-commerce scene : Hinder the integration of stand-alone applications ,“ seckill ” Are deployed in one WAR The inside of the bag , In that case , When a large number of requests rush in at a high speed , Unable to identify which traffic is seckill , Which is the traffic of normal pages , It is likely that promotional activities have affected normal network access . Consider the situation , We have to put more detailed granularity into the system to think , specifically , It is necessary to extend a module separately , Not as a whole “ In general ” Expand ( Although it has been clustered ). Gradually, a kind of “ Business split ” The technical means of , Use independent processes to host some business logic , It can be expanded in more detail , More scalable . Such a single business perspective can be understood as a further deepening of distributed applications .
A distributed task can be regarded as a service (Service), Each server node only completes this kind of service , More focused . This is not only the requirement of performance optimization , At the same time, it is also an urgent need to rationalize the architecture . Just imagine , A system has forums, mailboxes and chat rooms , It involves user login and user center , Because they are deployed separately , Not only resources are repeatedly wasted, but also management is not easy . So in order to overcome the above problems , Various ideas and methodologies such as distributed service have been introduced into large-scale projects .
Microservice style architecture
The deep distributed architecture is characterized by business splitting ( Service split ), Form a stronger connection than the cluster network 、 Closer network . In the past, our learning and working environment was to put all the code in one project , Package when deploying WAR Upload the package to the server , This is the single machine structure . Even if it evolves into a cluster structure , The actual work is to deploy several more servers, but the code is basically the same , There is no need to make too big changes . But after entering the current distributed structure , The old code has to be modified according to the communication problems between several independent processes .
Suppose it is still an example of a mall , According to the idea of microservice , We need to split it into multiple independent services according to functional modules , Such as : Customer service 、 Product service 、 Order service 、 Background management services 、 Data analysis services and so on . Each service can be independent Web Container or database , Even these services can be written in different languages ( Such as Java/PHP/Go/Node.js etc. ).
In the past single machine structure , One module calls another module , It's as simple as a function calling another function , No violation and no affectation , Cross process calls are rarely made , There is no service registration only for microservices 、 Find out . But after the service-oriented transformation of business splitting , More questions to consider , Distributed network topology 、 Network reliability 、 Communication mechanism and other contents have become the topic of our attention . inevitably , Services need a mutual communication mechanism to communicate , This is RPC(Remote Procedure Call) Called .
The benefits of microservices are : Say goodbye to strong coupling 、 chaos 、 General large-scale system , Dissolve into one “ Small service ”, Be able to expand and maintain a module in a targeted way , For example, the example of the above mall , Just increase the number of nodes in the order module and the seckill module before promotion , And the background system can maintain its original ability ; In addition, because of decoupling 、 So the modules can be easily replaced . The benefit of microservices is the reuse of modules with the structure , That's understandable , It's like splitting independent functions , Code reuse can be realized . This is not due to performance , It's the benefits of sorting out after business service .
In order to solve the problem that cannot be solved by cluster, a distributed microservice is proposed . Generally speaking, there is no silver bullet level panacea for microservices , Is still “ Divide and rule (Divide and Rule)” Philosophy of . On the other hand , In order to solve one problem, more problems are introduced to overcome . Is it worth it ? Once the microservice transformation or implementation is unsuccessful , Often not “ Change numerous for brief ” It is “ Simple things become complicated ” 了 , Do more harm than good . This is not a logical paradox , Or the eternal golden rule : In short, it depends on the choice of needs , When clustering is really not enough , Just go to wechat .
When it comes to microservices, I have to mention that they existed more than ten years ago SOA(Service -Oriented Architecture), There are many overlapping concepts with microservices , but SOA The disadvantages of this method are as follows ESB( The service bus ) and WebService The burden of subclasses is heavy . Microservices , seeing the name of a thing one thinks of its function , It is characterized by “ minute ” Each sub service constitutes a large system , Relatively lightweight .
边栏推荐
- [fastjson1.2.24 deserialization vulnerability principle code analysis]
- Dynamic performance view overview
- Traversal mode of list, set, map, queue, deque, stack
- A clear summary and configuration example of GPON has been highlighted
- Lnmp+wordpress to quickly build a personal website
- 1. MySQL Architecture [MySQL advanced]
- Abnormal (2)
- MySQL implementation plan
- Distributed system and distributed database system (Introduction)
- 2022-07-14 group 5 Gu Xiangquan's learning notes day07
猜你喜欢

Parameterization of JMeter performance test using CSV file

Rack server expansion memory

Software engineering -- dental clinic -- demand acquisition

Introduction to arrays -- array

AQS implementation principle

【 fastjson1.2.24反序列化漏洞原理代码分析】

数组的介绍--Array

Burp suite Chapter 3 how to use burp suite agent

Lambda and stream

This is a picture
随机推荐
Strtus2历史漏洞复现
Spotty music data client_ ID account
Shardingjdbc pit record
2W word detailed data Lake: concept, characteristics, architecture and cases
Audio and video learning (10) -- PS streaming
Logical volume management (LVM)
Abstract classes and interfaces
Solution to the problem of token loss when microservice feign is called
Using ordered dictionary to copy pcap files
The bigger the project is, the bigger it is. This is how I split it
Web side 3D visualization engine hoops communicator reads 10g super large model test | digital twin Technology
99 multiplication table and inverted triangle 99 multiplication table
Traversal mode of list, set, map, queue, deque, stack
OSPF总结
Database foundation
2022-07-13 group 5 Gu Xiangquan's learning notes day06
2022/7/1
The difference between LinkedList and ArrayList
2022-07-09 group 5 Gu Xiangquan's learning notes day02
Command line execution and test report generation of JMeter performance test