当前位置:网站首页>What you must know about distributed systems -cap

What you must know about distributed systems -cap

2022-06-24 10:26:00 Juvenile deer

          CAP The theory is discussed in the distributed cluster environment , Why does there exist in distributed cluster environment CAP The problem? ? for instance , Suppose our back-end storage service uses Redis middleware , If only one is deployed Redis The server , So this one Redis If you hang up , The entire storage service is down , So we want to improve its availability , What shall I do? ? The simplest way is to add machines :

Usability :

To put it simply, you can set up a cluster to prevent problems in the single machine deployment service , The entire system is directly unavailable , Set up a highly available cluster to prevent a node from going down , The other points can continue to provide services . Such as redis High availability cluster for , When a primary node goes down , Services can be provided through other nodes

Uniformity :

Consistency can be divided into strong consistency , Weak consistency , Final consistency , The consistency referred to here means strong consistency , Ensure that the data read at the same time is consistent . For example, the client updates a piece of data to the service at a certain time (set key =1 original key The value is 0), Then the client performs a read operation , At this time, you should ensure that the data read is 1 It should not be 0( Because in the case of cluster set Update the requested server and read The read servers are not the same )

Zone tolerance :

    Partition means , In distributed systems , Different nodes are distributed in different subnetworks , For some special reason , There is a state of network impassability between these sub nodes , But their internal sub network is normal . As a result, the environment of the whole system is divided into several isolated areas , This is the division .

      When you save a data item in only one node , After the partition appears , The part that is not connected to this node will not be able to access this data . At this time, the partition is intolerable . The way to improve partition tolerance is to copy one data item to multiple nodes , So after the partition , This data item may be distributed in different areas , Tolerance is increased .

Let's analyze with the diagram below Why must partition tolerance be guaranteed , Now let's assume that partition tolerance is not guaranteed , Guarantee AC, As shown in the figure :

      If partition occurs , Obviously, the cluster does not provide external services , This is definitely not in line with our design , Only when no partitions appear , To provide services . But the cluster service is difficult to guarantee ( It's basically impossible , Highly available services must be cluster deployment ).

Ensure partition availability , The cluster deployment is analyzed as follows :

If you promise P, It shows that the cluster can only start from A and C Choose one , Why? ? Let's focus on step 4 in the above figure , stay B node read num The operation of the value .

CP: If the client is not allowed to read at this time B Node num value , Then it is not available at this time , Only the client can read A node , stay A In nodes M The value is really the client Set num = 1 value ,num Value consistent , Now it's CP Model , Availability abandoned .

AP: If you can let the client read B Node num value , Then the node is available , But the read value num=0, If another client reads next time A Node num value , But I read num=1,Mnum Inconsistent values , Now it's AP Model , Consistency is abandoned

CAP Reference resources : Distributed theory ( One ) - CAP Theorem - Nuggets

Why? Nacos Configuration center to use CP Model ?

           CP The model sacrifices a certain delay in exchange for strong consistency of data , However, the externalized configuration of an application does not require a low delay for successful configuration , The more important thing is to ensure the consistency of configuration information ( My configuration information A = 1, Don't lose it or check it later A It's not equal to 1, cause X service A = 1,Y service A = 0 It happened , These are inconsistent data , This is definitely not going to work ), Therefore, in this configuration scenario, it is very suitable for CP Model


Why? Nacos The registry should use AP Model ?

        This question can also be translated into why the registry uses AP Model . Because availability is more important than consistency , Usability is reflected in two aspects , The first is the number of cluster downtime allowed ,AP In the model, only when all the machines in the cluster are down will it be unavailable ,CP The model only allows half of the machines to go down . The second is whether the partition is writable , for example A The computer room and B The machine room is partitioned , Unable to make network call , stay CP The lower part of the model is deployed in A The service of the computer room cannot be deployed , because A The computer room cannot communicate with B Computer room communication , So... Cannot be written IP Address , stay AP Under the model , Can be decentralized , It's like Eureka That way, even if partition occurs, each machine can write , There are no clusters Master, Instead, they copy their services to each other IP Information , such , Write is still supported when partitioning . Unavailability will cause the call between microservices to lose IP Address , And then the business collapses , So unavailability is unacceptable , Inconsistencies will cause different micro services to get IP Different addresses , It will cause load imbalance , This is acceptable .

BASE The theory is Basically Available( Basic available ),Soft State( Soft state ) and Eventually Consistent( Final consistency ) Abbreviations of three phrases .BASE It's right CAP The result of the trade-off between consistency and availability , It comes from the summary of the practice of large-scale Internet distributed system , Is based on CAP The law evolved gradually . The core idea is that even if strong consistency cannot be achieved , But each application can be based on its own business characteristics , Only then makes the system hit the final consistency with the appropriate way .

原网站

版权声明
本文为[Juvenile deer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206240921387053.html