Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of Mysql master-slave delay

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you what the master-slave delay method of Mysql is, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

1. Endure the Dafa

The first solution is very simple, there is no other, regardless of him, did not read it is fine. At this time, the business does not need any transformation. Hello, I am good, and she is all right.

If the business does not have high requirements for data consistency, we can adopt this scheme.

two。 Data synchronous write scheme

The master-slave data synchronization scheme generally uses the asynchronous mode to synchronize to the standby database.

We can modify it to the synchronization scheme, the master-slave synchronization is completed, and the writes on the master library can be returned.

The business system initiates the write operation, and the data is written to the main database.

The write request can not be returned until the master-slave synchronization is completed.

The data is read from the slave database, and the latest data can be read after the master-slave synchronization is completed.

In this scheme, we only need to modify the synchronization configuration between databases, and the business layer does not need to be modified, which is relatively simple.

"however, because master library writes need to wait for master and slave to complete, the latency of write requests will increase and the throughput will decrease. "

This may not be acceptable to the current online business.

3. Selective compulsory reading

For scenarios that require strong consistency, we can operate all read requests on the main library, so that "both reads and writes are in the main library" and there are no inconsistencies.

The business layer of this scheme needs to be reformed to make it mandatory, which is relatively difficult to transform.

However, this scheme increases the pressure on the main database rather than wasting another database.

4. Middleware selection routing method

This scheme requires the use of a middleware in which all database operations are first sent to the middleware and then distributed to the corresponding database.

The process is as follows:

Write the request, and the middleware will send it to the main library, and record the key of the write request at this time (operation table plus primary key, etc.)

Read request. If key exists at this time, it will be routed to the main library.

After a certain period of time (empirical value), the middleware thinks that the master-slave synchronization is completed, delete the key, and the subsequent reading will read the slave library.

This scheme can maintain the consistency of data reading and writing.

However, with the addition of a middleware in the system architecture, the overall complexity becomes higher, the business development becomes complex, and the learning cost is relatively high.

5. Cache routing Dafa

This scheme is similar to the scheme flow of middleware, but the transformation cost is relatively low and no middleware is needed.

The process is as follows:

The write request is sent to the master database, and the key of the record operation is cached, and the cache expiration time is set to the master-slave delay.

The read request first determines whether the cache exists.

If it exists, it means that a write operation has just occurred, and the read request operates on the main database

If it does not exist, it means that no write operation has occurred recently, and the read request operation is performed from the database.

The cost of this scheme is lower than that of middleware, but we introduce a cache component at this time, which adds one more cache operation between all reads and writes.

We introduce the master-slave architecture and the separation of data reading and writing, in order to solve the bottleneck of database reading caused by the rapid development of business, the increase of requests and the increase of concurrency.

However, when a new architecture is introduced to solve the problem, it is bound to bring another problem. After the separation of database read and write, the master-slave delay leads to data inconsistency.

In order to solve the problem of master-slave delay and data inconsistency, we can adopt the following solutions:

Endure the Dafa

Database synchronous write scheme

Selective compulsory reading

Middleware selection routing method

Cache routing Dafa

The above is what the master-slave delay method of Mysql is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report