MySQL Replication Latency Issues in wp-admin pages

You didn’t mention a HyperDB revision so I’m assuming trunk @337290.

HyperDB’s SRTM feature (send reads to master) works two ways. First, it keeps track of which tables have received writes during the current script and sends all subsequent reads for those tables to the master. Second, it gives you a way to force all reads to the master.

In the first case, it is still possible for a read to hit the slave after a write to the same table. If the read is a join query or another kind of query that can place table names far from the beginning of the query, it might slip through. If you can inspect the query that is improperly going to the slave, see if that’s the case. If so, try increasing the substr length here:

if ( preg_match($pattern, substr($query, 0, 1000)) )

It’s important to understand that the SRTM feature only keeps track during one script. So if you write a record (in 1st script) and then get redirected (now in 2nd script) and then try to read that record back out of the database, you will probably be reading from the slave on that second script.

Lastly, let me address the is_admin() idea. It’s a fine idea, simple and effective. Add something like this to your db-config file:

if ( is_admin() )
    $wpdb->send_reads_to_masters();

Leave a Comment