当前位置:网站首页>What do we talk about when we talk about the registry

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

Concept

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 .

Feature details

Storage

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 .

High availability

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

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 .

Service exploration

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 .

Routing functions

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 .

zookeeper

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

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 .

Reference resources


WeChat official account " Master bug catcher ", Back end technology sharing , Architecture design 、 performance optimization 、 Source code reading 、 Troubleshoot problems 、 Step on the pit practice .

版权声明
本文为[roshilikang]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/09/20210909112309728p.html

随机推荐