Advances in technology development is development from CP to AP

CAP principle not remember

C: Consistency

A: Availability

P: partition fault tolerance

C represents the strong consistency, A represents the availability of, P behalf of a partition when something goes wrong the entire cluster is still available.

Why is the development of progressive metal from CP to AP it?

Because C will consume considerable resources, in the case of large high concurrent data, the cluster will give more business support, but fear of the enemy cluster is strong consistency, especially in replicate mode, all clusters under the same copy, the performance loss will be huge. For example, we have a cluster are object A, B, C, D, E, the total amount of each cluster has a copy of the cluster is to reduce the pressure reading, so that reading dispersed to five instances. So, when added to an A data, you need to inform the other four instances, and, after determining four instances, no problems, returned to the A, to inform end synchronization instance, the entire cluster will become available. This is the middle there are several situations:

Scheme 1: A synchronized to the B, C, D, when the E, A is available, that is, A is a full-volume data, BCDE is no, then we can make A whether to provide services, while BCDE prior to receiving the full amount of data hiding outside, the entire instance that is available at this time, and only A to provide services, it will not be very good? Not only solved the timeliness, highly available clusters have let it? In fact there is a hidden risk, A when synchronizing data, there is IO output, and this process if a large number of read and write operations, IO resources are usurped, there will clog; that is, outside of the IO a will cause instability, will lead to a lot of other instances of a synchronization delay occurs, or read speed is very slow, the worst case, a crash, lose all the data read and write.

Scheme 2: A synchronization before B, C, D, on the E, the entire cluster is unavailable. The benefits of the cluster will be relatively stable, maintaining strong consistency, the downside is obvious, in this process, the cluster does not provide services not yet available, this is done C, you can not do the A. For example: ZK

Scheme 3: A synchronization to B, B to A is determined when the synchronization is complete, A to provide services, B to synchronize the asynchronous C, D, E, to achieve final uniformity. The advantage is, A B synchronized to the stability is much better than all synchronized to the cluster, the risk of dimension reduction 1 / N, one only need to select the best communication performance of the network as a B, all done by the B synchronization when the synchronization is complete, wake instance, to provide services. MYSQL default currently using this program.

The above three programs, in fact, are in the description of how to provide a CP cluster program, but in fact, CP here is not purely CP, we completed the internal synchronization mechanisms such clusters by AP.

With the development of the Internet, the program replicate less, fragmentation scheme Sharding more and more, and the high availability cluster, sharding + replicate manner (from a master 2) will be used, but never deviate which were nothing but a similar manner to achieve synchronization effect.

But the business, it is impossible to write business in the table to play for this high availability mode, so that we in the business, will consider putting more into synchronous asynchronous, the CP transformed into AP, the strong consistency into eventual consistency.

        For example: Scene paid after successful payment, we need to wait for a callback, delayed callback because we can not control, so in general the company will use a state machine to maintain this state to retry, eventually ensure successful execution.

        There example, in order to allow our business to support high-concurrency, synchronization will be possible to transform into an asynchronous, that is, unless it is before and after the strong dependence of the call, or I will solve asynchronous way, there are two commonly used asynchronous way, mq and asynchronous thread (to the current events elegant writing asynchronous threads available hystrix).

        As an example, commodity details page on the actual business, we analyze from the business, product details page which is necessary attributes, that is to say, without these attributes, product details page did not need to show; that I have listed here: merchandise inventory commodity prices which at least two are required; and product images, names, descriptions, even without these, as long as I can guarantee the success of the next single user, then it is not strongly dependent on factors, therefore, we will obtain information on product details page, inventory, if the acquisition fails, throw an exception to the upper layer directly capture; and product images, descriptions, names, and we pass asynchronous thread (hystrix) go to concurrent access, set the response time 1s, that is, I just waiting for 1s If you do not give me 1s, I think the return is null. In this way, it is a very efficient interface.

        This business scenario is actually very interesting, it is worth us to think more about the future and everyone I will share more and more such applications, in addition to the lack of chart paper, I am a bit too lazy to draw, the next opportunity I supplemented on .

Reproduced in: https: //www.jianshu.com/p/7c6d0a1ef5d1

Guess you like

Origin blog.csdn.net/weixin_34072458/article/details/91246011