What do we talk about when we talk about the registry
2021-09-15 04:25:04 【roshilikang】
This article has been included https://github.com/lkxiaolou/lkxiaolou welcome star.
Recently, the focus has shifted to the registry , So I wanted to write an article about the registry
What is a registry , As most people are familiar with RPC Frame speaking , Usually RPC There are three kinds of characters ：
provider Service providers
consumer Serving consumers , That is, the caller
registry Registry Center , Give Way consumer Can find provider The key to
The registry needs service registration for service providers 、 The ability to write off , For service consumers need to provide query services 、 The ability to perceive service change . Of course, there are other issues that need to be addressed to be a good registry , If available 、 High performance 、 Horizontal expansion capability 、 Service detection ability 、 Routing functions 、 Multiple computer rooms （ How to live ） Ability, etc .
You can think of a registry as a storage system , It stores the mapping table between the service name and the service provider . thus it can be seen DNS Is currently the most widely used registry . The general registry has no storage requirements , You can even implement a registry based on a database .
Before talking about high availability , Suppose you know Distributed CAP theory , If you don't know, you can check it online a little bit , I won't go into details here .
Among them, the high availability requirements for the registry are particularly high , It has the following meanings , First of all, it must be cluster deployment , No single point , Second, even if the whole cluster fails , It can't affect the call of existing services , It's just that the existing calling relationship can't be changed in time .
In distributed theory CAP in , The ideal registry would be AP Pattern .（ This conclusion is discussed in more detail at the end of the paper 《 Why not Alibaba ZooKeeper Service discovery 》）, It can be easily understood from the following two scenarios ：
There is no effect when the registry hangs up a node , If the registry is CP Pattern （ Strong consistency ）, image ZAB、raft agreement , They have a “ Elector ” The process of , Generally, the cluster is not writable when the master is selected
If the cluster appears “ Split brain ” The situation of , hypothesis 5 The node of the brain is divided into 3+2,CP In mode 2 Nodes will be completely unavailable , If consistency is sacrificed , At least make sure that the nodes are accessible , The impact on the service should be much less than the total unavailability
Horizontal expansion means that if the scale goes up , Can we pass With the machine To solve performance problems , At this point ,AP The pattern is also better than CP Patterns are easier to extend ,CP Pattern writing usually occurs at the master node , So the extension becomes very cumbersome , If the writing can be spread to different nodes , It's extensible , In terms of the simplest database implementation , It can be considered that it can be expanded horizontally , After all, the database can be written by sub database and sub table or distributed database .
Before we talk about service exploration, we need to introduce the dimensions of service registration , Dimensions affect exploration . Generally speaking , There are two dimensions of service registration ： Service dimension and application dimension .
Service dimension ： Register the interface to ip、port The mapping relation of , Such as dubbo（dubbo The new version also supports application level service discovery , But most of them are still using the service dimension service discovery ）, The advantage is that the registration information has nothing to do with the application , It's easy to split Services , The disadvantage is that the granularity is too fine , Large amount of registration data .
Application dimension ： Registered is applied to ip、port The mapping relation of , Such as spring cloud, The advantage is that the amount of registration data is small , The disadvantage is that it is difficult to split the service
There are usually two ways of probing , One is that the server takes the initiative to explore life , The other is that the client reports the heartbeat . It's very simple to explore application level services , As long as you determine whether the port is alive, you can judge the survival of the application , So the server can take the initiative to explore the solution ; But the service dimension is not , Generally, there is no existing way to know whether the service is alive or not , So if you want the server to actively explore life , need RPC The framework exposes the interface to inform the server of the surviving services , Or take the client to report the heartbeat to inform which services are alive .
Usually, the client actively reports to know whether the service is alive or not , But the server can't take the initiative to explore life , Sometimes the port is in , It doesn't necessarily mean that the service is alive . It's another question , Probing And Probe death The problem of , Detection of death is usually straightforward , It's hard to detect , If the port is not there, it must be dead , But the port is not necessarily alive .
What we have to say about exploration is the choice of methods , Usually different business requirements are different , Check if the port exists , Try to establish a connection , Request a health check interface, etc , This piece of nacos Well done , The detection mode can be expanded according to the demand , It also has a lot of detection methods built in .
This item is not required , But with it, it's strong .
For example, many companies have multiple environments , Such as development 、 test , Advance , The online environment , Usually the development and testing environment is deployed separately , But online and pre launch don't have to be deployed separately . Think of a registry without routing capabilities , If you want to call online only online , Pre - issue only calls pre - release , Is it necessary to deploy two sets of registries （ With zk For example ）. But if you add a routing function to the registry , on-line consumer Online only provider, Advance consumer Only pre paid provider, So you just need to deploy a set of environments .
Of course, routing capability is not limited to this , It can also solve the problem of multiple computer rooms calling nearby , You can even do a lot more imaginative , Something more interesting .
Multi room support
In fact, from the above description, we have found that , If you need to support multiple computer rooms ,CP It's a better choice , It is better to use the routing ability to solve the problem of multi machine room nearby call , Suppose there is A、B Two computer rooms ,X Service is only in A Room deployment ,Y The service is A、B The computer room has deployment , If X call Y, The best option is to call A Computer room Y Not farther away B Computer room .
Multi machine room is to deploy a set of registration center , Or each computer room has a set of registration centers ？ In fact, both options can be , To deploy a set of registration center, it is necessary to ensure that the service registration of each computer room should request this registration center , Stored data is a copy of , Such a problem is that the inter machine room call delay is high , But if it's a dedicated line , It's not a big problem either . If each computer room has a registry , There is no delay problem , But it is impossible that every computer room does not need to perceive the services of other computer rooms , This requires a data synchronization mechanism , Data synchronization means that there is a delay between registration and discovery , And the data consistency guarantee of multi center is more complex .
How to make technology selection
If you choose open source products , Is it in line with the company's technology stack 、 whether cover Living will be the first choice , For example, using dubbo, Which registries are right for dubbo Our support is more friendly ？ Which registries are java Technology stack ？
The second is the need for special capabilities of the registry , For example, the business is developing at a high speed , Performance and horizontal scalability need to be considered ; If you want to do some traffic control in the registry , Consider whether the selected registry has routing capability ; If you want to quickly and accurately remove the faulty machine , Then we need to consider whether the service detection capability of the registry can meet the demand ; There are many demands for the construction of computer rooms , We need to consider whether the registration center is friendly to multiple computer rooms , Do you support “ Call nearby ” Other characteristics .
Of course, open source products have their own merits , A common image zookeeper、nacos、eureka、consul etc. , The scenes encountered by large factories are usually more complicated , They usually customize their own registry , Like ants sofa-registry、 Hungry Huskar、 US mission MNS、 Commendable Haunt.
Here's an introduction zk and nacos To end with .
zk Is in dubbo The most used registry in , But it wasn't born to serve discovery itself .
It is based on ZAB agreement Implementation of a reliable distributed coordination system , It's strong consistency （CP）、 Using a TCP Private protocol communications for . because ZAB In the protocol, the write can only be initiated by the master node , So writing can only be done on a single machine , So horizontal expansion is difficult , It also doesn't support multiple computer rooms 、 Routing management and other functions .
zk The data in is similar to the tree structure of the file system , There are two kinds of nodes , One is the temporary node , One is the permanent node , Temporary node cannot save data , Permanent nodes can hold data , The temporary node will be removed after a long time of disconnection between the server and the client .
One sentence summary ：dubbo The first choice , Small and medium-sized enterprises are suitable for
nacos It is the registration center of Alibaba open source & Configuration center , As a registry, it uses self-developed distro agreement , A kind of AP The agreement , See the previous article for details 《nacos Consistency agreement for distro Introduce 》.
It can be used now http and dns Protocol to access nacos, The future may be through grpc To visit , Can expand horizontally , But the current performance is not high , In the future, there will be improvement after long connection , Multiple computer rooms can be expanded by CMDB Module to achieve , Support weight 、 Protection threshold and other load balancing strategies .
The community also provides nacosSync Tool to migrate other registries to nacos Registry Center , For migration practices, check out this article 《zookeeper To nacos The migration practice of 》
One sentence summary ： Characteristic ratio zk Enrich , But open source soon , stability 、 Not enough performance .
WeChat official account " Master bug catcher ", Back end technology sharing , Architecture design 、 performance optimization 、 Source code reading 、 Troubleshoot problems 、 Step on the pit practice .
- Garde la distance.
- 90 lines of code to implement the module packer
- When the OrCAD schematic is opened, suddenly the schematic file cannot be found
- Purpose and difference between Maitreya clamp and active clamp of IGBT
- [PHP source code] z-blogphp pirate navigation theme template
- Architecture and data science behind hundreds of thousands of experiments a year
- 大廠Android面試總結 詳細解答，Android技術圖譜
- Résumé de l'entrevue Android de Dachang, carte technique Android
Le résumé de l'entrevue Android de Dachang est en retard
Agent de cache SQUID
6 - year New Bird Development interview Byte Jumping Android R & D Post, Dry goods collation
Notes d'étude de HongMeng, 714 pages PDF, or, neuf, argent et dix
L'offre de la grande usine est douce. Incroyable.
L'offre d'une grande usine est douce.
L'intervieweur demande toujours le mode adaptateur et le mode d'apparence.
- Où est la sortie professionnelle pour les programmeurs d'usine après 35 ans?
- Stockage de produits Cloud packages, illimité et gratuit
- Opencv4 machine learning (VI): principle and implementation of k-means
- [yolop interpretation] you only look once for panoramic driving perception
- Tencent Cloud et d'autres systèmes de protection préférentiels
- Nombre maximum de points en ligne droite
- [interpretation of pointpillars] fast encoder for point cloud target detection
- [rangenet + + interpretation] fast and accurate lidar semantic segmentation
- [yolof interpretation] you only look one level feature (CVPR 2021)
- [SNE roadseg interpretation] pavement segmentation network combined with surface normal vector (eccv2020)
- [yolox interpretation] anchor free target detector comparable to yolov5!
- Opencv4 machine learning (4): geometric transformation and affine transformation of images
- Detailed explanation of fast SCNN semantic segmentation network
- Comparison of location loss functions in target detection network: IOU, giou, ciou, Diou, L1, L2, smooth L1
- Blue Bridge Cup software provincial competition in April 2021: title + analysis (full version)
- [C + + cultivation plan] don't talk about learning, just talk about dry goods (Day1)
- Tf2.0 deep learning practice (1): handwritten numeral recognition for classification problem
- Invitation | réunion Apache Pulsar 2021 - Shenzhen ce samedi
- The Dot Net Application Domain Study
- Trigger study
- Universal code, achieving with action -- Safety code scanning Professional Committee
- N'osez pas vous opposer à l'intervieweur et obtenir des commentaires personnels des stagiaires d'offer Ali après cinq rondes d'entrevue.
- Daniel prend le meilleur résumé de l'année pour rendre votre expérience d'application plus soyeuse.
- Easy to use and convenient development team management tool -- apipost
- Comment passer une entrevue avec une entreprise Internet de première ligne, Android Classic Getting started tutoriel
- Comment essayer un développeur Android vraiment niveau, 【 résumé de l'entrevue 】
- Ad redefines PCB size
- [wonderful learning journey of cloud computing] phase I: getting to know cloud computing for the first time
- Sf58-asemi high voltage fast recovery diode in-line package
- Asp.net quick build application page main framework
- Soul painter: cartoon illustration SSH
- Special live broadcast of the first anniversary celebration of Hongmeng community · invitation letter
- Mathematics Interview Questions (X)