The early MySQL Fabric sharding support for PHP

Posted by Unknown on Friday, March 7, 2014

The MySQL Fabric framework brings two major features: automatic client- and server-side failover and sharding. The manual hints, you need a “Fabric aware driver” for this but it does not list one for PHP. First, you don’t necessarily need new drivers! Second, the "driver" for PHP is the current development version of the PECL/mysqlnd_ms replication and load balancing plugin. The plugin covers the sharding but not the failover/HA quickstart example of Fabric: how the plugin works and why you should not use the plugin – yet.


Partial replication: the unlimited mode


At some point divide-and-conquer is the only know strategy to scale database replication. A huge data set must be devided into smaller sets that are distributed over many servers. There are middleware, in-core and hybrid architectures for such a system. The Fabric approach could be described as a middleware approach: a middleware manages servers and data distribution, clients talk to the middleware to learn about servers. Such an architecture minimizes the dependencies on the database. Power users can easily adapt the middleware to their needs.


PECL/mysqlnd_ms now also handles the "learn about servers/shards" part in the background. It talks to Fabric through XML RPC over HTTP.






































MySQL Fabric PHP application
mysqli/PDO_MySQL
<->learn about servers/shardsPECL/mysqlnd_ms
| |


  • Provision: masters and slaves

  • Monitor: load, health/failover

  • Balance: clone, merge, split shards




  • Connect and query


| |
MySQL servers

The client view: all the standard MySQL APIs


PECL/mysqlnd_ms is a client-side proxy which tries to hide as much of the complexity of using any kind of MySQL cluster (MySQL Replication, MySQL Cluster, 3rd party, MySQL Fabric sharding/HA) from the developer. This includes tasks such as load balancing, read-write splitting, failover and so forth. In the most basic case it is entirely transparent on the API level (mysqli, PDO_MySQL). Given the appropriate configuration, this is a load balanced connection, the SELECT goes to the slaves, the DROP to the master…



$link = new mysqli("myapp", "user", "password", "db");
$link->query("SELECT 1");
$link->query("SELECT 2");
$link->query("DROP TABLE IF EXISTS test");



What happens is that mysqli respectively PDO_MySQL extensions call functions in the mysqlnd library. PECL/mysqlnd_ms plugs in to the mysqlnd library to hooks these calls. If, for example, mysqli_connect() tries to open a connection to the host myapp, PECL/mysqlnd_ms captures the call and checks it config for an entry named myapp. Let the entry be for a MySQL Replication cluster. Then, later when mysqli_query() is executed, the plugin inspects the query and picks the a master or slave from the config to run the query on. Connecting the acutal servers is (mostly) transparent from an application user perspective as you can see from the code example.
















userspace – *.phpmysqli_connect(…)
inside PHP – ext/mysqlnd/*.cmysqlnd_connect(…)
inside PHP – ext/mysqlnd_ms/*.cconnect_hook(…)1) read server list from file: fopen(file://…)

The PHP manual has all the details, including the pitfalls and why you can


Truncated by Planet PHP, read more at the original (another 8821 bytes)




more

{ 0 comments... » The early MySQL Fabric sharding support for PHP read them below or add one }

Post a Comment

Popular Posts