I have read some articles, using the masterslave mode to implement read/write separation to improve mysql performance. The way is that webserver writes data to the master, and the master and slave are synchronized, then the webserver reads from the slave and I don't understand why this method improves performance? Because the master needs to work with slave... I have read some articles and use the master/slave Mode to implement read/write splitting to improve mysql performance.
The implementation method is that the web server writes data to the master, the master is synchronized with the slave, and then the web server reads data from the slave.
I don't understand why this method improves performance? Because the master needs to be synchronized with the slave, this means that all the (write) Statements executed on the master will be executed again on the slave, isn't this equal to the same load and read efficiency of slave and master?
Is the implementation method of the read/write method incorrect, or is there something I don't understand? Please kindly advise. Thank you!
Reply content:
I have read some articles and use the master/slave Mode to implement read/write splitting to improve mysql performance.
The implementation method is that the web server writes data to the master, the master is synchronized with the slave, and then the web server reads data from the slave.
I don't understand why this method improves performance? Because the master needs to be synchronized with the slave, this means that all the (write) Statements executed on the master will be executed again on the slave, isn't this equal to the same load and read efficiency of slave and master?
Is the implementation method of the read/write method incorrect, or is there something I don't understand? Please kindly advise. Thank you!
1. Increase in physical servers and Load
2. The master and slave nodes are only responsible for writing and reading each other, which greatly mitigates the contention between the X lock and the S lock.
3. The myisam engine can be configured from the slave database to improve query performance and save system overhead.
4. as for all the (write) Statements executed by the master, they will be executed once in the slave. This is only half of the statement, there is still a difference between synchronizing data from the master database and directly writing data from the master database. The binlog sent from the master database restores data. However, the most important difference is that the binlog sent from the master database to the slave database is asynchronous, restoring data from the database is asynchronous.
5. read/write splitting is applicable to scenarios where reading is much greater than writing. If there is only one server, when there are many select statements, the update and delete statements will be blocked by the data in these select statements. Wait until the select statement ends, low concurrency performance. For applications with similar write and read ratios, dual-master replication should be deployed.
You can refer to the following discussion:
Http://www.itpub.net/thread-1184103-1-1.html
The main points are as follows:
- Increase Redundancy
- Increased machine processing capability (increased hardware resources)
- For read-only applications, using read/write splitting is the best scenario ..... because it can ensure that the write server is under less pressure .... while reading can accept latency at a certain point in time
I know two aspects:
- We can add some parameters when starting the slave database to improve its read performance, for example, -- skip-innodb, -- skip-bdb, -- low-priority-updates, and -- delay-key-write = ALL. Of course, these settings are also determined based on specific business needs and may not be used.
- Distribute read. For example, if we have one master and three slave databases, we will not consider the slave database's unilateral settings mentioned in the preceding 1. Suppose there are 10 writes and 150 reads in one minute. Therefore, the number of reads from a master database 3 is equivalent to a total of 40, but the total number of reads remains unchanged. Therefore, on average, each server undertakes 10 writes and 50 reads (the master database does not perform read operations ). Therefore, although the write speed remains unchanged, the read speed is greatly apportioned, improving the system performance. In addition, when the read is apportioned, The Write Performance is indirectly improved. Therefore, the overall performance has been improved. To put it bluntly, we can change the performance of machines and bandwidth. The official MySQL documentation contains related calculation formulas: for official documentation, see "when and how MySQL replication can improve system performance" in 6.9FAQ.
In addition, another major function of MySQL replication is to increase redundancy and improve availability. When a database server fails, you can adjust another slave database to restore services as quickly as possible, therefore, you cannot simply look at the performance. That is to say, one master and one slave can also be used.
You should understand that after multiple slave instances, the number of concurrent accesses is less, and the number of established connections is less, so it is faster. If 5000 requests come and you say they all access the master server, the pressure on one server is 5000. If there are 10 small ones, each server is only 500, I estimate that the master server does not set an index because it only writes data to it. The speed of index creation, insertion, modification, and deletion will be affected. The master server does not perform any query operations anyway, if you do not want to index or create less indexes, the write efficiency may be higher.