Intro to PECL/mysqlnd_ms (4/7/2011)
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Intro to PECL/mysqlnd_ms (4/7/2011)

on

  • 9,538 views

I gave this presentation about the totally awesome mysqlnd_ms PHP extension at the Minnesota PHP User Group.

I gave this presentation about the totally awesome mysqlnd_ms PHP extension at the Minnesota PHP User Group.

Statistics

Views

Total Views
9,538
Views on SlideShare
7,747
Embed Views
1,791

Actions

Likes
7
Downloads
57
Comments
0

15 Embeds 1,791

http://blog.ulf-wendel.de 1292
http://www.cb1inc.com 447
http://www.planet-php.net 23
url_unknown 7
http://localhost 5
http://www.phpeye.com 4
http://www.slideshare.net 4
http://translate.googleusercontent.com 2
http://mailreader.163.com 1
http://www.hanrss.com 1
http://planet-php.org 1
http://www.blog.ulf-wendel.de 1
http://php5.planet-php.org 1
http://planet-php.net 1
https://twitter.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Intro to PECL/mysqlnd_ms (4/7/2011) Presentation Transcript

  • 1. Intro to PECL/mysqlnd_msChris BarberMinnesota PHP User GroupApril 7, 2011
  • 2. About MeChris BarberLead Software Engineer @ AppceleratorCEO/Technology Consultant @ CB1, INC.JavaScript, PHP, C++http://www.cb1inc.com@cb1kenobi on Twitter, Slideshare
  • 3. What is mysqlnd?
  • 4. What is mysqlnd?MySQL Native Driver for PHPPHP 5.3+Replaces libmysqlUsed by ext/mysql, ext/mysqli, PDO_MYSQLUse configure options: --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlndNot compiled into Ubuntu’s PHP 5.3 package :(
  • 5. What is mysqlnd_ms?
  • 6. What is mysqlnd_ms?A PHP Extension that provides transparent MySQLload balancing across master and slave servers
  • 7. How it worksCreate a mysqlnd_ms_config.ini with your settingsMake MySQL calls from your PHP codeINSERT, UPDATE, & DELETE statements go to masterSELECT statements go to slaves
  • 8. Getting started
  • 9. php.iniextension=mysqlnd_ms.somysqlnd_ms.enable=1mysqlnd_ms.ini_file=mysqlnd_ms_config.ini
  • 10. mysqlnd_ms_config.ini[myapp]master[]=192.168.1.120slave[]=192.168.1.121slave[]=192.168.1.122
  • 11. PHP Usage<?php$db = mysqli(“myapp”, “user”, “password”);$results = $db->query(“SELECT ...”);$db->query(“INSERT ...”);?>
  • 12. Which server to connect to?
  • 13. Choosing a serverAvailable load balancing algorithms: random round-robin user defined (custom PHP function) random_once (sticky)Specify algorithm in the mysqlnd_ms_config.ini file
  • 14. Choosing a server [myapp] master[]=192.168.1.120 slave[]=192.168.1.121 slave[]=192.168.1.122 pick[]=user pick[]=random<?phpfunction pick_server($connected_host, $query, $master, $slaves, $last_used_connection) { if (stristr($query, “FROM table_a”)) return “hostname_of_slave_for_table_a”; return NULL; // resort to random/random-once/round-robin}mysqlnd_ms_set_user_pick_server(“pick_server”);?>
  • 15. Issues...
  • 16. IssuesINSERT and immediate SELECT Replication lagTransactions Need server stickinessFailover
  • 17. Hints Prefix query with a comment!<?php$db = mysqli(“myapp”, “user”, “password”);$results = $db->query(“/* HINT_GOES_HERE */SELECT ...”);?>
  • 18. Built-in Hints MYSQLND_MS_MASTER_SWITCH MYSQLND_MS_SLAVE_SWITCH MYSQLND_MS_LAST_USED_SWITCH MYSQLND_MS_ALL_SERVER_SWITCH MYSQLND_MS_QUERY_USE_MASTER MYSQLND_MS_QUERY_USE_SLAVE MYSQLND_MS_QUERY_USE_LAST_USED
  • 19. Hints<?php$db->query(sprintf(“/*%s*/SET @a=1”, MYSQL_MS_SLAVE_SWITCH));$db->query(sprintf(“/*%s*/SET @a=@a+1”, MYSQL_MS_LAST_USED_SWITCH));$db->query(sprintf(“/*%s*/SELECT @a as _a”, MYSQL_MS_LAST_USED_SWITCH));?>
  • 20. Custom Hints<?phpfunction pick_server($connected_host, $query, $master, $slaves, $last_used_connection) { if (preg_match("@^/*.+*/@ismU", $query, $matches)) { $json = json_decode($matches[1]) if ($json && $json->something_enabled) { return “some_special_hostname”; } } return NULL; // resort to random/random-once/round-robin}mysqlnd_ms_set_user_pick_server(“pick_server”);$db->query(“/* {“something_enabled”:true} */SELECT ...”);?>
  • 21. Server Picking Ideas Geo-load balancing Routing around server maintenance Sharding Dynamically add/override master/slave hostnames
  • 22. Failover mysqlnd_ms does not do failover Do it in your application! Retry query N number of times before falling on sword Have pick_server() “disable” dead servers for a minute Perhaps use APC to cache which servers are dead
  • 23. Getting mysqlnd_mssvn co http://svn.php.net/repository/pecl/mysqlnd_ms/trunk mysqlnd_mscd mysqlnd_msphpizeconfiguremakesudo make install
  • 24. More InfoAuthors: Andrey Hristov, Ulf Wendel, & JohannesSchlueterhttp://blog.ulf-wendel.dehttp://svn.php.net/viewvc/pecl/mysqlnd_ms
  • 25. ThanksQuestions?