Although we are in a front end, we can’t avoid some obscure terms coming out of the back port: microservices, clustering, distributed, load balancing, MQ, Redis, kafka, etc. Today’s focus is on understanding clustering and distribution.
Let’s start with a simple business history. Now, a small e-commerce startup company wants to build an e-commerce system. With a bang, the business development is completed and Tomcat is deployed online.
When the volume of business is small, a machine access nature is not what any problem, I can carry.
As the company’s business volume gradually increases, the original server can not carry, how to do?
There are hundreds of schools of thought
Let’s first look at how to longitudinally expand to solve the problem plus configuration plus configuration plus configuration, 8 cores 16,16 G on 64G, not 128G so can be infinite increase configuration, think about it is impossible, after all, the single machine is the upper limit. Moreover, if you configure a double, the CPU’s computing power will not double, and the increase rate will gradually decrease. There is a very important concept in economics: diminishing marginal utility
This should be easy to understand, like the company started junior programmers can not handle, switch to senior, senior can not, switch to experts. So since you can’t plow deep in the vertical direction, you have to plow horizontallyHorizontal scalingAdd servers, one can not come to two, two is not enough to come to one.
All these server groups together form a cluster
Of course, there is a need for a special machine to do scheduling, such as Nginx and the like. With so many machines at work, who should deal with them? Here I think of the thread pool in Java, so many workers, need a dispatcher to distribute.
So there are no limits or drawbacks to just increasing the machine infinitely? , of course, is impossible, first of all, though there are so many servers, but on each server to deploy the code is the same, your order goods logistics system of a complete set of data processing is really all in a single server processing, the processing capacity of a machine, after all, there is a cap, so is there any good way? Yes, we can’t add it on the hardware, so we have to optimize it on the software. We can vertically subdivide the services on a machine, such as commodity service, search service, order service and user service. Can they be separated from each other? We can only deal with one thing on a machine.
Let professional people do professional things
The deployment of each individual service is essentially distributed and the only things that are needed are communication between services, RPC calls and messaging mechanisms. This is just like the development process of our mobile terminal. We start with a module and then move into modularization, module by function, RPC framework based on SPI mechanism for cross-module communication and EventBus message component.
In the end, is this the end? If a machine to deal with a service is not enough, right, then let’s level expansion once again, ten machines run a service, service continues to tear down small, often repeated, endless also.
In life, there are many examples of this pattern.
- A roadside stall with a hand grasping cake, a man in charge of collecting money, making and selling cakes, a complete stack of engineers.
- Business is good, customers are more, and then upgrade to a small shop, with cashiers, waiters, cooks. One person becomes three, and that’s distributed.
- With more clients, one chef isn’t enough, so hire two more. So three chefs is a horizontal expansion into a cluster.
- Jay Chou is the endorsement of your hand-scratch cake. Some people in a store can’t eat hand-scratch cake all day long. In the expansion, opening chain stores, multiple stores is a dimension of the cluster.
- It is not efficient for each store to produce hand-held cakes separately, so the store cluster mode is transformed into a distributed one. The facade store is only responsible for selling, while the specialized kitchen is responsible for producing and then sending them to the store for selling.
- .
In fact, in reality, many enterprises are indeed like this. When I matched glasses before, I chose the frame in the store, and then the machine directly matched the glasses for you in one hour. The last time I matched glasses was in SOHO. I found that they could not get the glasses that day, because there was no machine in their shop. They were only responsible for selling glasses. So everyone who sells glasses knows about distributed deployment services, hahaha.