Why a slave machine is faster to read than a master in database replication

In master / slave database replication, all records go to the master machine. All readings go to the slave machine. The master machine replicates data to the slave. When the master replicates the data to the slave, the slave computer must make a record that locks the row. Reading from a slave machine is faster, but why?

+4
source share
2 answers

Master is very busy

  • It writes data in parallel (which is obvious)
  • This results in writing I / O to disk in binary logs, serializing the complete SQL collection to its binary logs
  • It manages replication in terms of transferring completed SQL from its binary logs to the slave's I / O stream (visible on Master through SHOW PROCESSLIST; with the username system user ). This may slow down a little, since the slaves are connected to the wizard.

The Vedas are less busy because they ...

  • Serialize I / O for MySQL Replication
    • Collects SQL from the master through an input / output stream
    • Writes SQL from IO Thread to its latest relay log
    • SQL Thread reads the next available SQL from relay logs
  • Handles one SQL command / one transaction at a time through an SQL stream
  • If Slave had all MyISAM and Master all InnoDB , entries in Slave tables with foreign key constraints would not have required any referential integrity checks. No MVCC has to happen in Slave.

The only exceptions that would put Slave and Master on the same playing field would be

  • If the slave device has binary logging. This is not required if the slave is a slave, but it is necessary if the slave was also a master.
  • If multiple SQL statements were handled as a single InnoDB transaction.
  • If the equipment is different
    • The wizard has faster disks, more cores, more RAM.
    • Slave was a commodity server
+3
source

The slave must be much faster because:

  • The volume of recorded data coincides with the main
  • Writing to the subordinate bypass of all syntax and permissions checks (everything that works - and this is a lot - is performed by the master when processing the request - only data changes are sent to the subordinate)
  • It does not read anything else other than what you perform as a test.
  • Replication is an optimized process designed for the highest possible synchronization speed, therefore, if we have a master failure, shaving is as relevant as possible. This means that by design it should cause as little work as possible on the slave.

All this means that the slave is under significantly less load than the master.

In fact, redirecting reads to the slave is a known performance modification.

+3
source

Source: https://habr.com/ru/post/1440867/


All Articles