mysql read-write separation

http://heylinux.com/archives/1004.html

https://blog.csdn.net/justdb/article/details/17331569

1. What is read-write separation

One of the most powerful functions of MySQL Proxy is to achieve "Read/Write Splitting". The basic principle is to let the master database handle transactional queries and the slave database handle SELECT queries. Database replication is used to synchronize changes caused by transactional queries to slave databases in the cluster. Of course, the main server can also provide query services. The biggest effect of using read-write separation is nothing more than environmental server pressure. You can see this picture:
write picture description here

The benefits of separation of reading and writing

1. Increase redundancy

2. Increase the processing power of the machine

3. For applications that are mainly read, using read-write separation is the best scenario, because it can ensure that the server pressure for writing is less, and the reading can accept a little time delay.

Three reasons why read-write separation improves performance

1. The physical server increases and the load increases
. 2. The master and slave are only responsible for their own writing and reading, which greatly alleviates the contention of X locks and S locks
. 3. The slave library can configure the myisam engine to improve query performance and save system overhead
. 4. There is still a difference between synchronizing the data of the master library from the slave library and writing directly from the master library. The data is restored through the binlog sent by the master library. However, the most important difference is that the master library sends the binlog to the slave library asynchronously, and the recovery of data from the slave library is also asynchronous. 5. The read-
write separation is suitable for the scenario where the read is far greater than the write. If there is only one server, when there are many selects, the update and delete will be blocked by the data accessed by these selects, waiting for the end of the select, and the concurrent performance is not high. For applications with similar write and read ratios, dual-master mutual replication should be deployed

6. You can add some parameters to improve the read performance when starting from the library, such as –skip-innodb, –skip-bdb, –low-priority-updates and –delay-key-write=ALL. Of course, these settings also need to be determined according to specific business needs, and may not be used.

7. Apportioned reads. Suppose we have 1 master and 3 slaves, regardless of the unilateral setting of the slave library mentioned in 1 above, assuming that there are 10 writes and 150 reads in 1 minute. Then, 1 master and 3 slaves are equivalent to a total of 40 writes, but the total number of reads has not changed, so on average, each server undertakes 10 writes and 50 reads (the master library does not undertake read operations). Thus, while writes are unchanged, reads are greatly amortized, improving system performance. In addition, when the read is amortized, the performance of the write is indirectly improved. Therefore, the overall performance has improved. To put it bluntly, it is to exchange the performance of the machine and bandwidth. There are relevant calculus formulas in the official MySQL documentation: For the official documentation, see "When and to what extent MySQL replication can improve system performance" in 6.9FAQ

8. Another major function of MySQL replication is to increase redundancy and improve availability. When a database server goes down, it can restore the service at the fastest speed by adjusting another slave database, so it cannot only look at performance, that is to say 1 master 1 slave is also possible.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324383969&siteId=291194637