Oracle 5.0 Reference Manual page 2590

Table of Contents

Advertisement

Mysqlnd replication and load balancing plugin (mysqlnd_ms)
Example 20.234. Maximum age/slave lag
{
"myapp": {
"master": {
"master_0": {
"host": "localhost",
"socket": "\/tmp\/mysql.sock"
}
},
"slave": {
"slave_0": {
"host": "127.0.0.1",
"port": "3306"
}
},
"failover" : "master"
}
}
Example 20.235. Limiting slave lag
<?php
$mysqli = new mysqli("myapp", "username", "password", "database");
if (!$mysqli)
/* Of course, your error handling is nicer... */
die(sprintf("[%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()));
/* Read from slaves lagging no more than four seconds */
$ret = mysqlnd_ms_set_qos($mysqli,
MYSQLND_MS_QOS_CONSISTENCY_EVENTUAL,
MYSQLND_MS_QOS_OPTION_AGE, 4);
if (!$ret)
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
/* Plugin picks any slave, which may or may not have the changes */
if (!$res = $mysqli->query("SELECT item, price FROM daytrade"))
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
/* Back to default: use of all slaves and masters permitted */
if (!mysqlnd_ms_set_qos($mysqli, MYSQLND_MS_QOS_CONSISTENCY_EVENTUAL))
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
?>
The eventual consistency service level can be used with an optional parameter to set a maximum slave
lag for choosing slaves. If set, the plugin checks
case of the example, only slaves for which Slave_IO_Running=Yes,
and
Seconds_Behind_Master <= 4
item, price FROM
Checking
SHOW SLAVE STATUS
any, are reported as warnings. No error will be set on the connection handle. Even if all
SQL statements executed by the plugin fail, the execution of the users statement is not
STATUS
stopped, given that master fail over is enabled. Thus, no application changes are required.
Expensive and slow operation
Checking
It is an expensive and slow background operation. Try to minimize the use of it.
Unfortunately, a MySQL replication cluster does not give clients the possibility to
is true are considered for executing the statement
daytrade.
is done transparently from an applications perspective. Errors, if
SHOW SLAVE STATUS
2570
SHOW SLAVE STATUS
for all slaves adds overhead to the application.
for all configured slaves. In
Slave_SQL_Running=Yes
SELECT
SHOW SLAVE

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents