当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Normal equation

Juul, the American e-cigarette giant, suffered a disaster, and all products were forced off the shelves

numpy. linspace()

Record the range of data that MySQL update will lock

希尔排序图文详解+代码实现

Flink checkPoint和SavePoint

使用swiper左右轮播切换时,Swiper Animate的动画失效,怎么解决?

形状变化loader加载jsjs特效代码

Leetcode-1823: find the winner of the game

【JS逆向分享】某个网站社区信息
随机推荐
2.登陆退出功能开发
【数据分析数据源】全国各省市行政区坐标(包含边界坐标点和中心坐标点)
SSM整合
线程池的执行流程
用扫描的方法分发书稿校样
Why is JSX syntax so popular?
4. classification management business development
Leetcode interview question 01.05: primary editing
Status of the thread pool
leetCode-面试题 01.05: 一次编辑
【资源分享】2022年第五届土木,建筑与环境工程国际会议(ICCAEE 2022)
Customize the toolbars of the kindeditor editor. Items removes unnecessary toolbars or retains some toolbars
What are the characteristics of EDI local deployment and cloud hosting solutions?
时尚的弹出模态登录注册窗口
numpy. logical_ or
2022年智能机器人与系统国际研讨会(ISoIRS 2022)
【IEEE出版】2022年工业自动化,机器人与控制工程国际会议(IARCE 2022)
SQL sever基本数据类型详解
解决微信小程序rich-text富文本标签内部图片宽高自适应的方法
【JS逆向分享】某个网站社区信息