MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
Upcoming SlideShare
Loading in...5
×
 

MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4

on

  • 12,073 views

Clustering MySQL is a mainstream technology to handle todays web loads. Regardless whether you choose MySQL Replication, MySQL Cluster or any other type of clustering solution you will need a load ...

Clustering MySQL is a mainstream technology to handle todays web loads. Regardless whether you choose MySQL Replication, MySQL Cluster or any other type of clustering solution you will need a load balancer. PECL/mysqlnd_ms 1.4 is a driver integrated load balancer for PHP. It works with all APIs, is free, semi-transparent, at the best possible layer in your stack and loaded with features. Get an overview of the latest development version 1.4.

Statistics

Views

Total Views
12,073
Views on SlideShare
3,571
Embed Views
8,502

Actions

Likes
6
Downloads
89
Comments
0

41 Embeds 8,502

http://blog.ulf-wendel.de 5365
http://www.planet-php.net 1103
http://asyncionews.com 909
http://planet-php.net 229
http://www.ulf-wendel.de 175
http://ulfwendel.de 142
http://ulf-wendel.de 116
http://blog.ulfwendel.de 93
http://planet-php.org 69
http://www.ulfwendel.de 57
http://www.planet-php.org 57
http://cloud.feedly.com 37
http://www.phpeye.com 27
http://www.twylah.com 17
http://www.newsblur.com 12
http://localhost 11
http://feedreader.com 10
http://dev.newsblur.com 10
http://blog.planet-php.org 10
http://phpeye.com 9
http://translate.googleusercontent.com 6
http://php5.planet-php.org 6
http://www.hanrss.com 3
http://inoreader.com 3
http://www.tuicool.com 3
http://php.oss-tohoku.org 2
http://blog.ulf-wendel.de.myrademo.net 2
http://127.0.0.1 2
https://twitter.com 2
http://www.blog.ulf-wendel.de 2
http://wall.bit-tests.1and1.com 2
http://www.google.de 2
http://ulf-wendel.de.myrademo.net 1
http://xianguo.com 1
http://reader.aol.com 1
http://plus.url.google.com 1
http://webcache.googleusercontent.com 1
http://mbo.drigger.com 1
http://www.phpeye.com&_=1338983580625 HTTP 1
http://www.btekd.com 1
http://digg.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4 MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4 Presentation Transcript

  • Ulf Wendel, Oracle MySQL? Load?Clustering! Balancing! PECL/mysqlnd_ms 1.4
  • The speaker says...Clustering databases is a main stream technology.MySQL users can choose between a variety of clusteringoptions. The opions range from asynchronous primary copyto synchronous update anywhere.Lets quickly recap what MySQL has to offer.
  • MySQL Replication New: Global Transaction IdentifierAsynchronous read scale-out Master: writes, Slaves: reads Various topologies supported Other use cases: backup, HA, OLTP/warehousing Client Writes Reads Master Slave Slave Slave
  • The speaker says...MySQL Replication is used for read scale-out. Writesare send to a MySQL master, reads are send to a MySQLslave. The master sends updates to the slaves in anasynchronous way. Slaves may not have the latestchanges. This kind of replication is also called primary copy.Where goes the update: to the primary. When/how doupdates happen: lazy, asynchronous.MySQL Replication can also be used for:Backup – perfom blocking backup on slaveHigh Availablility – for example, remote slavesWarehousing – OLTP reporting on the slaves
  • MySQL Cluster 1.2 Billion UPDATEs/minReal-time transactional write scale-out 99,999% availability Auto sharding, shared nothing architecture Web use cases: session server, tele communication Client SQL Node SQL Node Cluster Data Node Cluster Data Node Cluster Data Node
  • The speaker says...MySQL Cluster is used for real-time transactionalread and write scale-out. Data is auto-partitioned oncluster data nodes resulting in 99.999% availability. Thecluster is accessed through MySQL Application ClusterNodes. The most basic MySQL Application Cluster Node is aSQL Node – a MySQL Server (mysqld).If MySQL Cluster is new to you, think of MySQL Cluster as astorage engine for the network. Like InnoDB and MyISAMare storage engines for disks. This kind of replication is alsocalled eager (when?) update anywhere (where?).
  • Application using any DB clusterTasks: Choose servers to execute statement Load balance within candidates Maintain connection pool Automatic (client) fail over for High Availability Client MySQL Server 1 MySQL Server 2 MySQL Server n
  • The speaker says...All PHP applications talking to a cluster of MySQLdatabase servers are facing the same tasks.Replacing a single database with a database cluster meanschanging the 1:1 relation between the application and thedatabase into a 1:n relation. 1:n puts an additional task onthe application: find the right n, find the right server totalk to.
  • The plugin for all of you WordPress, Drupal, Symfony, Oxid, ZendFramework, ... mysql, mysqli, PDO_MYSQL mysqlnd PECL/mysqlnd_ms pluginStatement Redirection Balancing Failover Connection Pooling MySQL Server 1 MySQL Server 2 MySQL Server n
  • The speaker says...PECL/mysqlnd_ms is a plugin for the MySQL nativedriver for PHP (mysqlnd) library. The mysqlnd library ispart of PHP as of version 5.3. As of 5.4 mysqlnd is a default.All three PHP MySQL APIs (mysql, mysqli, PDO_MySQL) canbe compiled to use the mysqlnd library, thus all existingPHP MySQL application are supported by the plugin.From an applications point of view a mysqlnd plugincan act as a transparent proxy. Depending on the usecase, no code changes are needed. PECL/mysqlnd_mscan be a drop-in solution.
  • Wait - whats wrong with this?Go for it! But dont miss our goodies...class DBRepl { private static $master_list = array(...); private static $master = NULL; private static $slave_list = array(...); private static $slave = NULL; public static function WriteConn() { if (self::$master) return self::$master; /* pick and initialize ...*/ } public static function ReadConn() { if (self::$slave) return self::$slave; /* pick and initialize ...*/ }}
  • The speaker says...A client-side approach to the problem is promising, ifclient applications can be changed. It is no drop-insolution. The load balancer is part of the clientapplication. It scales by client and it fails by client.There is no single point of failure as it is the case with aproxy based approach. No additional latency occurs like witha proxy. Load balancing can be adaptive for goodresource usage. DBMS node failures do not blockclients, fail over is possible.PECL/mysqlnd_ms has all this, is semi-transparentand offers many more features!
  • PECL/mysqlnd_ms 1.4Anything missing? All PHP MySQL APIs, semi-transparent, drop-in Read write splitting, transaction aware Load balancing, fail over (optional: automatic) Service levels: consistency, slave lag limit, trottling Optional, automatic caching of read results User can control all automatic actions 75+ pages documentation: hands on and reference Stable, more test code than C code Some 10 bug reports since 1.0
  • The speaker says...No worry, it is not complicated. All the magic is beneath thehood, in the C code of PECL/mysqlnd_ms. The userinterface is short and comprehensive.This is all what PECL/mysqlnd_ms is about: make usingany kind of MySQL Cluster easier! Let the load balancerdo the work.Provide a cluster-aware API. Clustering is mainstream. Weneed new APIs.
  • Read/Write splittingDefault: mysqlnd_ms.disable_rw_split = 0 read-only: statement begins with SELECT read-only: statement begins with slave SQL hint custom: callback picks slave for statement Client Writes Reads (SELECT, SQL hint) Master Slave Slave Slave
  • The speaker says...Read/Write splitting must be done for primary copy clusters,like MySQL Replication. Clients must direct all writes to theprimary (master). PECL/mysqlnd_ms automaticallydirects statements that begin with SELECT or acertain SQL hint to one of the configured secondaries(slaves).An update anywhere cluster, such as MySQL Cluster, allowswrites to be performed on all nodes. No read write splittingis needed. Thus, you can disable it on a global level usingthe configuration directive mysqlnd_ms.disable_rw_split.
  • Redirection and transactions No switch allowed during a transaction API calls controlling transactions monitored (5.4+) SQL not checked, protocol does not annnounce state Solution: use API (5.4+) or SQL hints! ClientUPDATE SET col=@my BEGIN; SELECT @my=1; Master Slave Slave Slave
  • The speaker says...Statement redirection for load balancing bares apitfall: connection state. Session variables andtransactions are part of the state. A load balancer must notswitch servers in the middle of a transaction. When usingprimary copy, all transactions shall go to the primary(master) because it is unknown at the beginning of atransaction whether it includes updates.The MySQL Client Server protocol does not hint whether atransaction is active. Load balancers must either parse SQLto catch BEGIN, monitor API calls or be hinted by theapplication. PECL/mysqlnd_ms monitors the API andunderstands hints.
  • Transaction aware codeUse API call over SQL to control transactions For MySQL Replication, set: trx_stickiness = master Check master_on_write=1 or mysqlnd_ms_set_qos()$mysqli = new mysqli("myapp", "username", "password", "database");/* Disable autocommit, master used, no server switch allowed */$mysqli->autocommit(FALSE);/* ... */if (!$mysqli->commit()) { die(sprintf("[%d] %sn", $mysqli->errno, $mysqli->error));}/* Transaction has ended, load balancing begins again */$mysqli->autocommit(TRUE);
  • The speaker says...Use the API calls to control transactions. Give thedatabase driver a chance to help you. Virtually any statechange that you perform through API calls is handledby PECL/mysqlnd_ms. For example, if you change thecharset with mysqli_set_charset(), the plugin makes surethat all opened connections use the same charset. We hidecomplexity, make cluster use easier.Consider using master_on_write=1. This will keep allreads followed by the first write on the master. Handy, ifyou use asynchronous cluster and eventual consistency isnot enough. Wait for quality-of-service, its gettingbetter!
  • Is this your code?PECL/mysqlnd_ms does not look worse, does it?$mysqli = DBRel::ReadConn();/* ... */$mysqli = DBRepl::WriteConn()$mysqli->autocommit(FALSE);/* ... */if (!$mysqli->commit()) { die(sprintf("[%d] %sn", $mysqli->errno, $mysqli->error));}/* ... */$mysqli->autocommit(TRUE);$mysqli = DBRepl::ReadConn();
  • The speaker says...The differences to the classic approach become obvious.The plugin code has less „hints“, the abstraction is less ofteninformed of the need of a certain type of database.The classic code is specifically written for a certain kind ofcluster. Once you migrate the database from a lazy primarycopy system (e.g. MySQL Replication) to an eager updateanywhere solution (e.g. MySQL Cluster) you have additionalcalls in your code that are no more needed.The plugin code needs nothing but a configurationfile change to switch from MySQL Replication toMySQL Cluster.
  • Load BalancingBuilt-in or user-defined through callback Round robin, Random, Random once 1.3 – kind of adaptive by setting limits for slave lag 1.4 – nodes can be assigned a weight/probability Client Writes Load Balancing of Reads Master Slave Slave Slave Weight = 1 Weight = 2 Weight = 1 Weight = 1
  • The speaker says...The best and default load balancing stategy is theone with the lowest impact on the connection state:random once. Minimize switches for the life-span of yourPHP script. Pick a random slave during startup and use it forall reads. The life-span of PHP is the of a web request. It isshort. Two web requests will end up on two random slaves.The upcoming 1.4 release will allow you to assign a weightto a node. Nodes with a weight of two will get twiceas many requests as nodes with a weight of one. Thisis not only great if your nodes have differentcomputing power but also to prefer local nodes overremote ones by setting a higher weight.
  • Pooling: connection failoverCaution: connection state change Default: disabled = raise exception Optional: silently failover master 1.4 – remember failed, try more slaves before master Client Writes Reads Master Slave Slave Slave
  • The speaker says...Connection state changes are what speaks againstautomatic, silent fail over once a connection hasbeen established and fails. If your application is writtenin a way that automatic reconnect upon failure is allowed,you can enable it. Otherwise, handle the error, do notclose the connection but run the next query totrigger a new load balancing attempt! Failed nodes canbe remembered for the duration of a request.Automatic failover can either try to connect to themaster or try to use another slave before failing overto the master. If using MySQL Cluster, the search logicstill applies with the only difference that only masters are tobe configured.
  • Pooling: lazy connectionsDo not open connection before needed Delay open until statement execution Reduce number of connections, reduce load Great for legacy apps – even without load balancing Client Writes Reads Master Slave Slave Slave
  • The speaker says...By default, to reduce the connection pool size ofevery PHP web request, connections are not openedbefore executing a statement. Imagine you have 50concurrent web requests, you configured four slaves and,you are using random once. If not using lazy connections,the plugin opens 50 x 4 = 200 slave connections but uses atmax 50 of them (random once). Every connection occupiesresources – ever seen a PHP application openingconnections before using? There are many badly writtenones...Many connection state changing API calls are buffered andreplayed when opening lazy to prevent pitfalls.
  • Quality of serviceDont bother about node selection – MS does! mysqlnd_ms_set_qos() Eventual, session and strong consistency Allow only certain slave lag, enable caching Client PECL/mysqlnd_ms Database cluster as a service Node Node Node Node
  • The speaker says...The basics (load balancing, failover) are solved. Abstractioncan start. We can start to see the cluster as a service. Theload balancer knows how to use the cluster to achieve acertain quality of service. The application formulates itsservice quality requirements, the load balancer takesappropriate action. For example, state the consistencylevel needed. Is reading stale data from a slaveallowed (eventual consistency) and if so, is there anylimit on freshness?Having API calls to know the client demands is agreat help for load balancer and cluster vendors!
  • Eventual consistencyNodes may or may not serve the latest copies Nodes may serve stale copies or not have copies at all Default consistency level of MySQL ReplicationSET X = 1 MySQL Node MySQL Node MySQL Node GET X, X = 0 GET X, NULL
  • The speaker says...An eventual consistent node may or may not servethe latest copy. In fact, there is no promise that aparticular copy is available from every node. Manysystems that default to eventual consistency reach strongconsistency over time. Eventually all nodes getsynchronized. This model is similar to that of a cache.Eventual consistency is good enoug for browsing productcatalogs or other infrequently changing contents in areaswhere stale data is acceptable. It is the default consistencylevel with MySQL Replication. Why bother ?! Cant vendorsprovide proper solutions?
  • Clustering databases is complexThere is no one-fits-all replication solution The dangers of replication and a solution (Jim Gray, Pat Helland, 1996): a ten-fold increase in nodes and traffic gives a thousand fold increase in deadlocks or reconciliations CAP theorem (Eric Brewer, 2000): consistency, availability and paritition tolerance cant be achieved together … vendors are forced to offer compromises … vendors are faced with a highly complex problem … you are forced to know about consistency :-(
  • The speaker says...I would love to stop talking about consistency. Butreplication has limits. Keep on pushing but know thelimits. Every synchronous, update anywhere solution has ascalability limit. Partitioning (sharding) only shifts the limitsand creates other issues (rebuilding aggregates). Until itssolved...Applications shall state their QoS/consistency needs:To allow vendors to relax consistency for performancereasons, but only if feasible, if allowed by the appTo allow load balancers to make an optimal node choice= PECL/mysqlnd_ms 1.2+ build around GTIDs...
  • Setting QoS for consistencyBetter than master_on_write = 1$mysqli = new mysqli("myapp", "username", "password", "database");/* read-write splitting: master used */$mysqli->query("INSERT INTO orders(item) VALUES (elePHPant)");/* Request session consistency: read your writes */mysqlnd_ms_set_qos($mysqli, MYSQLND_MS_QOS_CONSISTENCY_SESSION);/* Plugin picks a node which has the changes, here: master */$res = $mysqli->query("SELECT item FROM orders WHERE order_id = 1");var_dump($res->fetch_assoc());/* Back to eventual consistency: stale data allowed */mysqlnd_ms_set_qos($mysqli, MYSQLND_MS_QOS_CONSISTENCY_EVENTUAL);/* Plugin picks any slave, stale data is allowed */$res = $mysqli->query("SELECT item, price FROM specials");
  • The speaker says...An eager update anywhere replication system such asMySQL Cluster delivers strong consistency. Classicusers of MySQL Replication achieve different level ofconsistency using the simple rules: eventual consistency– any slave, session and strong consistency – masteronly.Using the master for any level beyond eventualconsistency has a negative impact on read scale out.MySQL 5.6 Global Transactions Identifiers help toachieve session consistency even when reading fromslaves – reliable read your writes has becomepossible. PECL/mysqlnd_ms implements the nodeselection logic.
  • Global transaction identifierCombination of server id and sequence number Emulation: PECL/mysqlnd_ms 1.2+, MySQL Proxy Built-in: MySQL 5.6 MySQL Master Log 7, Pos 34, GTID M:1: UPDATE x=1 Log 7, Pos 35, GTID M:2: UPDATE x=9 MySQL Slave 1 MySQL Slave 2 … , GTID M:1: UPDATE x=1 … , GTID M:1: UPDATE x=1 … , GTID M:2: UPDATE x=9
  • The speaker says...A global transaction identifier is a cluster-wideunique transaction identifier. MySQL 5.6 can generate itautomatically. MySQL Proxy and PECL/mysqlnd_ms 1.2feature client-side emulations for use with any MySQLversion. SQL can be used to access the GTIDs.GTIDs have been been created to make MySQL Replicationfailover easier. However, they are useful for load balancingas well in a primary copy system.
  • MySQL Replication: strong con.With or without GTID: primary only Only the primary has all comitted transactions Client A Client B MySQL MasterSET X = 1 GET X, X = 1 MySQL Slave MySQL Slave
  • The speaker says...Configuring PECL/mysqlnd_ms for use with a MySQLReplication cluster and calling mysqlnd_ms_set_qos($conn,MYSQLND_MS_QOS_CONSISTENCY_STRONG) instructsPECL/mysqlnd_ms to use only the MySQL Replicationmaster server for requests.In a lazy primary copy system there is only one node that isguaranteed to have all comitted updates: the primary.Please note, that its possible to achieve higher consistencylevels than eventual consistency in an lazy primary copysystem by appropriately choosing nodes.
  • MySQL Replication: session con. Use GTID to find „synchronous“ slave Check slave status using SQL Reduce read load on master SET X = 9 MySQL Master ..., GTID M:1: UPDATE x=1 ..., GTID M:2: UPDATE x=9GET X, X = 9 MySQL Slave 1 MySQL Slave 2 … , GTID M:1: UPDATE x=1 … , GTID M:1: UPDATE x=1 … , GTID M:2: UPDATE x=9
  • The speaker says...Global transaction identifier help to find „up-to-date“slaves that have already replicated the latestupdates of a client. Thus, session consistency cannow be achieved by reading from the master andselected „up-to-date“ slaves. This works with the GTIDemulation of PECL/mysqlnd_ms 1.2+ and any MySQLversion. And, it works with MySQL 5.6 that has built-inGTIDs.PECL/mysqlnd_ms 1.4 can either wait for a slave tocatch up or search all slaves before considering themaster. The wait effectively means throttling slavesto reduce slave lag!
  • MySQL Replication: eventual c.With or without GTID: all slaves Optional QoS level: upper slave lag limit MySQL estimates slave lag! SET X = 9 MySQL MasterGET X, X = 8 MySQL Slave 1 MySQL Slave 2 Slave lag = 1 second Slave lag = 7 seconds
  • The speaker says...A MySQL Replication slave is eventual consistent – itmay or may not have the latest updates. There is noneed to filter nodes with regards to consistency.Slaves can be filtered by replication lag:mysqlnd_ms_set_qos($conn,MYSQLND_MS_QOS_CONSISTENCY_EVENTUAL,MYSQLND_MS_QOS_OPTION_AGE, 5) filters out allslaves that report an estimated lag of more than fiveseconds.
  • Slave selection logicSame logic whenever slaves are to be filtered applied for: session consistency + GTID applied for: eventual consistency + Lag Stage 1: send SQL to check status to all slaves Stage 2: fetch replies in order Stage 3: apply filter logic SQL is documented in the manual
  • The speaker says...Whenever PECL/mysqlnd_ms has to check the slave statusfor filtering slaves, the check is done in two stages. First, allslaves are queried. Then, replies are fetched from the slavesin order. Usually, many requests can be send out in stageone before the servers reply.The SQL details are documented at php.net/mysqlnd_ms.
  • QoS: Cache Integration Automatically cache data no older than n seconds Reduce slave load Caches: Memcache, process memory, … PHP 5.4, PECL/mysqlnd_qc 1.11st GET X, X = 8 MySQL Slave 1 MySQL Slave 2 Slave lag = 1 second Slave lag = 7 seconds Max_TTL = 10 – 1 = 1 TTL = MAX_AGE - 9 TTL = MAX_AGE - 72nd GET X, X = 8 Cache
  • The speaker says...If the load balancer knows that eventual consistencyis good and a certain degree of stale data (age, slavelag) is allowed, a slave access can be transparentlyreplaced with a cache access. This lowers the overallslave load in the cluster and reduces latency.Replacing a slave access with a cache access istransparent from an application point of view.PECL/mysqlnd_ms is using PECL/mysqlnd_qc (qc = querycache) for the caching. PECL/mysqlnd_qc can also be usedas a standalone cache to store query results in Memcache,process memory and many more caches.
  • Transparent caching$mysqli = new mysqli("myapp", "username", "password", "database");/* no caching */$res = $mysqli->query("SELECT headline FROM latest_news");var_dump($res->fetch_all(MYSQLI_ASSOC));/* use cache, if slave lag allows */mysqlnd_ms_set_qos($mysqli, MYSQLND_MS_QOS_CONSISTENCY_EVENTUAL, MYSQLND_MS_QOS_OPTION_CACHE, 60));$res = $mysqli->query("SELECT headline FROM old_news");var_dump($res->fetch_all(MYSQLI_ASSOC));
  • The speaker says...Complicated logic behind but easy to use – PHP shouldlook out for new cluster aware APIs.Lets close with an example of a minimal configuration foruse with MySQL Replication.
  • Speaking code: configuration/* php.ini */mysqlnd_ms.enable=1mysqlnd_ms.config_file=/path/to/mysqlnd_ms_plugin_json.conf/* /path/to/mysqlnd_ms_plugin_json.conf contents */{ "myapp": { "master": { "master_0": { "host": "localhost", "socket": "/tmp/mysql.sock" }}, "slave": { "slave_0": { "host": "192.168.2.27", "port": "3306"}}}}
  • Connect and use... - as ever$mysqli = new mysqli("myapp", "username", "password", "database");$pdo = new PDO(mysql:host=myapp;dbname=database, username, password);$mysql = mysql_connect("myapp", "username", "password");/* Statements will be run on the master */$mysqli->query("DROP TABLE IF EXISTS test");$mysqli->query("CREATE TABLE test(id INT)");$mysqli->query("INSERT INTO test(id) VALUES (1)");/* Goes to the slave - dont let slave lag fool you! */$res = $mysqli->query("SELECT id FROM test");var_dump($res->fetch_assoc());$mysqli->close();
  • The speaker says...Imagine we would have failover that could be bound tocertain error codes. For example, assume the SELECTreturns „Error: 1051 SQLSTATE: 42S02(ER_BAD_TABLE_ERROR), Message: Unknown table %s„ because you forgot about possiblity of a lag between theCREATE and on the master and the SELECT on the slave.What if PECL/mysqlnd_ms would automatically fail over tothe master to retry the SELECT... Sure, the better solution isto as for session consistency to avoid this issue at all.Let us know what additional features you would liketo see in PECL/mysqlnd_ms. We are ready to code...
  • THE ENDContact: ulf.wendel@oracle.com, @Ulf_Wendel
  • Kvack? Bonus slides!Load Balancing layers overview
  • Whole stack clusterSimple – 1:1 mapping! Requires synchronous cluster No fault tolerance: node failure = stack failure Inefficient resource usage: no balancing HTTP Server HTTP Server HTTP ServerApp Server (PHP) App Server (PHP) App Server (PHP) MySQL Node MySQL Node MySQL Node
  • The speaker says...In a synchronous cluster, for example, if using MySQLCluster, all nodes have all the data. Thus, every applicationserver could be assigned to one DBMS node. Easy, fastand good for MySQL Cluster but with limits. No goodfor asynchronous MySQL Replication.Limit: DBMS node failure includes application nodefailure. Client should have additional fail over logic.Limit: Over- and undercapacity of a DBMS nodecannot be compensated. Clients cannot switch to morepowerful nodes. Overcapacity of a MySQL node cannot beused by other clients. Different hardware size is ignored.
  • Proxy approach - ProFree and open source MySQL Proxy No application changes, free 3rd party proxy scripts MySQL node failure does not stop application server Good resource usage, dynamic adoption possible HTTP Server HTTP Server HTTP ServerApp Server (PHP) App Server (PHP) App Server (PHP) MySQL Proxy MySQL Node MySQL Node MySQL Node
  • The speaker says...A transparent MySQL Proxy based solution requiresno application changes. Clients connect to the Proxyusing MySQL Client Server Protocol, as if the MySQL Proxywas a MySQL Server.Proxy can compensate for DBMS failures. It can reactto temporary and permant outages.Proxy can adapt load balancing dynamically. Takinginto account node hardware size, current node load, latency,location, … fantasy sets the limits here for self-written or 3rdparty Proxy scripts.
  • Proxy approach - ConAdditional component Complex architecture, can be single point of failure C and Lua are no natural match for PHP lovers Adds latency: from client to proxy to node HTTP Server HTTP Server HTTP ServerApp Server (PHP) App Server (PHP) App Server (PHP) MySQL Proxy MySQL Node MySQL Node MySQL Node
  • The speaker says...MySQL Proxy is a great performer!But, … MySQL Proxy adds complexity to the stack.MySQL Proxy needs to be managed. MySQL Proxy is buildaround C and Lua. C and PHP would be a better match forPHP users. Wrongly used, MySQL Proxy becomes a singlepoint of failure. It is single threaded. This bares the risk oftasks (Proxy scripts) blocking each other.But, … MySQL Proxy adds latency. Although, it can beminimized significantly running MySQL Proxy on the AppServer to avoid use of TCP/IP between PHP and Proxy.
  • Client-side load balancer - ProClient application handles load balancing No single point of failure No additional latency Highly configurable and adaptive HTTP Server HTTP Server HTTP ServerApp Server (PHP) App Server (PHP) App Server (PHP) <?php .. ?> <?php ...?> <?php ?> MySQL Node MySQL Node MySQL Node
  • The speaker says...A client-side approach to the problem is promising, ifclient applications can be changed. It has most Pros ofthe previous approaches.The load balancer is part of the client application. Itscales by client and it fails by client. Scalability is givenand there is no single point of failure. No additional latencyoccurs.Load balancing can be adaptive for good resourceusage. DBMS node failures do not block clients, failover is possible.
  • Client-side load balancer - ConClient application handles load balancing Application must be designed for (specific) cluster use No drop-in solution for existing applications PHP is stateless: adaptive load balancing is difficult HTTP Server HTTP Server HTTP ServerApp Server (PHP) App Server (PHP) App Server (PHP) <?php .. ?> <?php ...?> <?php ?> MySQL Node MySQL Node MySQL Node
  • The speaker says...The major downside of a client-side applicationbased solution is the need to change the application.Application changes must be done even for basic cluster usecases. Modifications to source code may not be possible.They may complicate upgrades of standard software. Theymay cause lots of work thus become expensive.Load balancing is part of PHP thus stateless. This is both aPro and a Con. It is difficult to hint other clients about nodefailures. On the other hand, shared nothing is not a bad ideaeither.
  • Is driver based the solution?Client-side and driver based: PECL/mysqlnd_ms Pro: all previous Synchronous cluster: no application changes Asynchronous cluster: no change for basic cases HTTP Server HTTP Server HTTP ServerApp Server (PHP) App Server (PHP) App Server (PHP)PECL/mysqlnd_ms PECL/mysqlnd_ms PECL/mysqlnd_ms MySQL Node MySQL Node MySQL Node
  • The speaker says...A driver based client-side solution has all Pros!Considering load balancing aspect only, no applicationchanges are required. If using MySQL Cluster, asynchronous cluster, no application changes arerequired. If using MySQL Replication, anasynchronous cluster that needs read-write splitting,the need for application changes is significantlyreduced!The PECL mysqlnd_ms installation can be part of the nextPHP deployment, done anyway for security considerations.No new procedure. If any issues, simply disable extension.