当前位置:网站首页>[talkative cloud native] load balancing - the passenger flow of small restaurants has increased

[talkative cloud native] load balancing - the passenger flow of small restaurants has increased

2022-04-23 20:14:00 Letter brother blog

One 、 Preface

This is a 《 Big talk cloud 》 The second part of the series , Chapter one 《 Boiled dumplings and docker、kubernetes The relationship between 》 After the launch, it was welcomed by everyone , Many friends contacted me to cheer me up , thank ! I will continue to write !
The book goes on to introduce 《 Boiled dumplings and docker、kubernetes The relationship between 》 after , Xiao Na ( My wife ) ask : Why not develop services into one application ? What's going on ? It feels huge , It's complicated ? Why do you do this ? So the second part of the big talk cloud - Load balancing , now !

Two 、 Start with a roadside stall

I worked overtime on Friday night , It's late to get off work , Call Xiao Na and plan to have a barbecue , Just go to the one we often go to “ Husband and wife stall ” Barbecue . I didn't find out until I arrived “ Husband and wife stall ” The upgrade , Now it's “ Couple Restaurant ”. Because it's late , There are not many people in the shop , I chatted with the landlady . Talk about yesterday in a small restaurant 、 Today and tomorrow? !

The landlady introduced :“ At the roadside stall in front of us, we just got married , Limited funds in hand , Just want to open a roadside barbecue stand . My husband is responsible for baking kebabs and cooking , I? 、 Responsible for service cashier and serving . Make a little money !”. The landlady is modest , When I get old, I may also make a living as a kebab , Who makes me love to eat ! The landlady said that she was able to go to today , Mainly because of the following points :

  • Her stall rarely has the phenomenon of waiting for dishes for a long time . Because the capacity of tables, chairs and benches in stalls is usually limited , Usually not so many guests , The upper limit of the total demand for food is basically fixed , Relatively good coordination .
  • Smooth communication 、 Fast , This order string roars 、 It started over there . When you're ready, yell again , It's served .
  • short 、 Easy to turn around . The reason why the couple chose to start from the roadside stall , Because the boat is small and easy to turn around . It's possible to work for a while and find that there are few passengers in this location , You can stop operating immediately or operate in another place .

Ah , Don't say , At this stage, the couple is a bit like some software service startups , When I started my business , Generally, the application services are single applications . The author has also seen some small start-ups who want to engage in micro service cloud , I don't think it's realistic . The structure of the enterprise is developed step by step , Don't always think about eating a fat man in one bite . If Jingdong Taobao wants to be what it is today when it makes application services from the first day , They will not live to this day . Just like a person who has never opened a restaurant, he will open a five-star hotel for the first time , Nine times out of ten waiting for him is failure !

file

Here I'm talking about the characteristics of monomer application , In fact, it is similar to the characteristics of roadside stalls :

  • The number of requests that can be accepted is limited , First, there are not so many users in terms of demand , Second, the resources of start-ups are limited , Memory of the server 、CPU Configuration is limited .
  • View layer of monomer application 、 Control layer 、 The persistence layer is all in one application , Call convenient 、 Fast response . There are no remote calls between services RPC, Respond faster , Specific to a service request, the response result is faster .
  • Development of simple 、 Quick start 、 A team of three or five people is easy to manage and use . The boss decided to quit , You can turn around at any time , It doesn't hurt much .

Congratulations to the landlady , expert in making money , We will also sum up experience !

3、 ... and 、 Restaurant opening and load balancing

Some time ago, some people were willing to line up for the barbecue made by their husband and wife , The couple thought , We can't do it either , What do I do ? Hire someone 、 Expand the scale .

  • Recruit someone ? Chef, of course 、 The cashier's wife can do it by herself , The main reason is that the husband can't live , Yes , Then hire a cook .
  • Don't let more guests stand and eat ? Rent a nearby store 、 Add more tables, chairs and benches .

Same thing , What if the individual application service in the software application cannot meet the needs of users , Add servers , Deploy more services , Load balancing .

Talk about client-side load balancing and server-side load balancing

  • The little couple arranged three chefs for the restaurant ( Including husband ), That's enough . The wife will Order No To chef Zhang 、 Double order For chef li , Neither of them can do it , Then give the order to her husband . Anyway, outsiders don't have to pay for it , My family can take a break . She'll give it to whoever she says , She has her own algorithm . This pattern is “ Client load balancing ”, The wife calls... As a client “ The cook ” service , I'll remember how many chefs there are , Then forward the user request to one of the chefs according to its own algorithm . Our common Spring Cloud When each service requests other micro Services , Maintain a list of microservices inside , Then, according to the request target and algorithm, select a service from the micro service for remote service invocation .
  • One day the two chefs put forward their opinions : It's too tired to do this. There's no free time , Or the husband does more , Or get a raise . The couple are not very strong now , It's better for the husband to do more . Then the wife doesn't have to remember “ The single and even numbers of the order ” 了 , Just use one app Enter customer order , The app It can realize the balanced distribution of orders to chefs .“ This pattern is “ Server side load balancing ””. For software architecture, this app Load balancer , The commonly used software load balancers are nginx、haproxy etc. . There are also some hardware load balancers , Better performance , Of course, the charge is also more “ good ”. The architecture is shown in the following figure :

file

Advantages and disadvantages :

  • “ benefit ” That is, the processing capacity of the application has increased , Able to handle more orders .
  • “ Disadvantages ” The cost of communication has increased , The original problem solved by yelling , Now we need to rely on app Forwarded ( Load Balancer ). Whether it's a remote service call , Or request forwarding is time-consuming .

in other words : The hotel ( Application service ) The ability to handle request throughput is now enhanced , But the processing speed of a single request is actually reduced . In fact, this is the result of service splitting , Service splitting is in “ Trade time for space ” . Ladies and gentlemen !

Four 、 After dinner communication

After eating kebabs , I gave the above theory to Xiao Na , She's very interested in :“ Software architecture is really inseparable from real life , There are living examples everywhere ”. I took advantage of the situation to boast :“ Where is this , Next time I'll take you to a big hotel to see the world , Big hotels with micro Services !”.

Welcome to my blog , More boutique knowledge collection

Reprint of this article indicates the source ( Must be connected , You can't just turn words ): Alphabet blog - zimug.com

If it helps you , Give me some compliments 、 Share ! Your support is my inexhaustible creative power !. in addition , The author recently output the following fine content , Looking forward to your attention .

版权声明
本文为[Letter brother blog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210555444650.html