SlideShare a Scribd company logo
Yes, its the mysqlnd talk!
mysqlnd: Asynchronous Queries and more ... ,[object Object],[object Object],[object Object]
The MySQL PHP “Connectors” Andrey Hristov (Development - mysqlnd),  Johannes Schlüter (Development),  Ulf Wendel (QA) and Georg Richter (everything, somehow...)
How PHP connects to MySQL  PHP MySQL Server Library: implements MySQL Client-Server Protocol PHP API for PHP applications MySQL native driver for PHP / MySQL Client Library
The “MySQL native driver for PHP“ ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inside PHP (on the C level!) PHP Extensions Zend Engine PDO ext/mysql ext/mysqli SAPI PDO_MYSQL PDO_XYZ MySQL Client Library (libmysql)  or MySQL native driver for PHP (default as of PHP 5.3)
PHP and the MySQL Client Library ext/mysql ext/mysqli PDO_MYSQL PHP Memory: emalloc, * PHP Infrastructure IO: PHP Streams MySQL Server MySQL Client Library  Memory: malloc, * IO: read, write, ... Operating System
PHP and mysqlnd ext/mysql ext/mysqli PDO_MYSQL PHP Memory: emalloc, * PHP Infrastruktor IO: PHP Streams mysqlnd - MySQL native driver for PHP (PHP 5.3+) MySQL Server
Which API would you like?
Mixed Salad ext/mysql ext/mysqli PDO_MYSQL PHP mysqlnd (PHP 5.3+) MySQL Server MySQL Client Library  ,[object Object],[object Object],[object Object]
Advantage mysqlnd! ,[object Object],[object Object],[object Object],[object Object]
Read-Only Variablen (Copy on Write) <?php $row = mysqli_fetch_assoc($res); ?> MySQL Server 1M 1M 1M
Cheers – mysqlnd rocks!
Sharding – split and distribute ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How to split and distribute? Postings Categories Users Single DB Postings, thread_id%2 = 0 Categories Users Shard 1 Postings, thread_id%2 = 1 Categories Users Shard 2 Categories Users Shard 1 Postings Shard 2 Categories Users Shard 1 Denormalized: Postings with users.nickname Shard 2
Your problems... not mine... ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Where to split and distribute? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
“Transparent” Proxy with mysqlnd? ,[object Object],$mysqli = mysqli_connect(&quot;host&quot;, &quot;user&quot;, &quot;pw&quot;, &quot;db&quot;);  $stream = mysqli_conn_to_stream($mysqli); stream_filter_register(&quot;rewrite&quot;, &quot;rewrite_filter&quot;); stream_filter_append($stream, &quot;rewrite&quot;); $res = mysqli_query($mysqli, &quot;SELECT 1 AS _one&quot;); while ($row = mysqli_fetch_assoc($res)) var_dump($row); array(1) { [&quot;_one&quot;]=> string(1) &quot;2&quot; }
Query Rewriting with mysqlnd class rewrite_filter extends php_user_filter { function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { if (strstr($bucket->data, 'SELECT 1')) { $bucket->data = str_replace( 'SELECT 1', 'SELECT 2', $bucket->data); } $consumed += $bucket->datalen; stream_bucket_append($out, $bucket); } return PSFS_PASS_ON; } } ,[object Object]
Sharding - a forum example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Categories Users Shard 1 Postings with users.nickname, category_id % 2 = 0 Shard 2 Postings with users.nickname, category_id % 2 = 1 Shard 3
Your new problems... ,[object Object],[object Object],[object Object],[object Object],[object Object],Categories Users Shard 1 Postings with users.nickname, category_id % 2 = 0 Shard 2 Postings with users.nickname, category_id % 2 = 1 Shard 3
Show all postings of a user  $shard1 = mysqli_connect('shard1', ...); $res = $shard1->query('SELECT ... FROM users WHERE id = ...'); display_user($res);  $res->free_result(); $shard1->close(); $shard2 = mysqli_connect('shard2', ...); $res = $shard2->query('SELECT ... FROM postings WHERE ...'); display_postings($res);  $res->free_result(); $shard2->close(); $shard3 = mysqli_connect('shard3',...); $res = $shard3->query('SELECT ... FROM postings WHERE ...'); display_postings($res);  $res->free_result(); $shard3->close();
The basic idea PHP MySQL Server PHP MySQL Server PHP PHP PHP MySQL Server PHP MySQL Server PHP MySQL Server
New asynchronous API  boolean mysqli_query( string query,  MYSQLI_ASYNC) int mysqli_poll( array $connections,    array $except,   array $rejected,   int $tv_sec    [, int tv_usec]) mixed mysqli_reap_async_query( mysqli $connection)
Asynchronous “Show all ...” - I $shard1 = mysqli_connect('shard1', ...); $shard2 = mysqli_connect('shard2', ...); $shard3 = mysqli_connect('shard2', ...); $shard1->query('... FROM users ...', MYSQLI_ASYNC); $shard2->query('... FROM postings ...', MYSQLI_ASYNC); $shard3->query('... FROM postings ...', MYSQLI_ASYNC);
Asynchronous “Show all ...” - II $all_links = array($shard1, $shard2, $shard3); $processed = 0; do { $links = $errors = $reject = array(); foreach ($all_links as $link) $links[] = $errors[] = $reject[] = $link; if (0 == ($ready =  mysqli_poll($links, $errors, $reject, 1, 0)) continue; foreach ($links as $k => $link) { if ($res = mysqli_reap_async_query($link)) { mysqli_free_result($res); $processed++; } } } while ($processed < count($all_links));
Synchronous vs. asynchronous  1000ms 500ms 600ms 1000ms 500ms 600ms ,[object Object],[object Object]
$start = microtime(true); $m1 = mysqli_connect('host', 'user', 'password', 'schema'); $m2 = mysqli_connect('host', 'user', 'password', 'schema'); mysqli_query($m1, 'SELECT SLEEP(0.10)', MYSQLI_ASYNC); mysqli_query($m2, 'SELECT SLEEP(0.25)', MYSQLI_ASYNC); printf(&quot;Query  : %2.2fs&quot;, microtime(true) - $start); while ($processed < 2) { $links = array($m1, $m2); if (mysqli_poll($links, array(), array(), 0, 50000)) { foreach ($links as $k => $link) if ($res = mysqli_reap_async_query($link)) { mysqli_free_result($res); printf(&quot;Fetch %d : %2.2fs&quot;, ++$processed,    microtime(true) - $start); } } printf(&quot;Poll  : %2.2fs&quot;, microtime(true) - $start); } Is it faster? > sapi/cli/php mysqli_poll2.php Query  : 0.00s Poll  : 0.05s Fetch 1 : 0.11s Poll  : 0.11s Poll  : 0.15s Poll  : 0.21s Fetch 2 : 0.26s Poll  : 0.26s
$m1 = mysqli_connect('host', 'user', 'passwd', 'database'); $m2 = mysqli_connect('host', 'user', 'passwd', 'database'); mysqli_query($m1, 'SELECT SLEEP(0.10)', MYSQLI_ASYNC); mysqli_query($m2, 'INSERT INTO users(id) VALUES (100)', MYSQLI_ASYNC); while ($processed < 2) { $links = array($m1, $m2); if (mysqli_poll($links, array(), array(), 0, 50000)) { foreach ($links as $link) if (is_object($res = mysqli_reap_async_query($link))) { $processed++; mysqli_free_result($res); } else { $processed++; } } } Mixing SELECT and INSERT > sapi/cli/php mysqli_poll2.php Query  : 0.00s Poll  : 0.05s Fetch 1 : 0.11s Poll  : 0.11s Poll  : 0.15s Poll  : 0.21s Fetch 2 : 0.26s Poll  : 0.26s
$m1 = mysqli_connect('localhost', 'user', 'password', 'schema'); $m2 = mysqli_connect(&quot;localhost&quot;, &quot;user&quot;, &quot;password&quot;, &quot;schema&quot;); mysqli_query($m1, 'SELECT NIXNUTZ FOR PREDISENT', MYSQLI_ASYNC); mysqli_query($m2, &quot;SELECT 1&quot;, MYSQLI_ASYNC | MYSQLI_USE_RESULT); while ($processed < 2) { $links = array($m1, $m2); if (mysqli_poll($links, array(), array(), 0, 50000)) foreach ($links as $k => $link) { if (is_object($res = mysqli_reap_async_query($link))) { var_dump(mysqli_fetch_assoc($res)); mysqli_free_result($res); } else if (mysqli_errno($link)) printf(&quot;[%d] %s&quot;, mysqli_errno($link), mysqli_error($link)); else printf(&quot;no error, no result&quot;); $processed++; } } Handling Server errors > sapi/cli/php mysqli_poll_error.php array(1) { [1]=> string(1) &quot;1&quot; } [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PREDISENT' at line 1
$m1 = mysqli_connect('host', 'user', 'password', 'schema'); $m2 = mysqli_connect('host', 'user', 'password', 'schema'); printf(&quot;Connection %d: no query&quot;, mysqli_thread_id($m1)); mysqli_query($m2, 'SELECT 1',  MYSQLI_ASYNC | MYSQLI_USE_RESULT); printf(&quot;Connection %d: SELECT 1&quot;, mysqli_thread_id($m2)); while ($processed < 2) { $links = array($m1, $m2); $rejected = array($m1, $m2); if (0 == ($ready = mysqli_poll($links, array(), $rejected, 0, 50000))) continue;  foreach ($rejected as $link) printf(&quot;Connection %d: rejected&quot;, mysqli_thread_id($link));  $processed += count($rejected);  foreach ($links as $link)  printf(&quot;Connection %d: accepted&quot;, mysqli_thread_id($link)); $processed += count($links); } Detecting invalid handles > sapi/cli/php mysqli_poll_invalid.php Connection 205: no query Connection 206: SELECT 1 Connection 205: rejected Connection 206: accepted
if (mysqli_poll($links, array(), array(), 0, 5000)) foreach ($links as $link) { mysqli_reap_async_query($link);   if (mysqli_errno($link)) die(mysqli_error($link)); $all_links[mysqli_thread_id($link)]['inserted']++; if ($all_links[mysqli_thread_id($link)]['inserted'] < $rows) {   if (mysqli_query($link, $query, MYSQLI_ASYNC)) $i++; else  die(mysqli_error($link)); } } Daily bulk INSERT - ./ me! (Part1) > sapi/cli/php mysqli_poll_bulk_insert.php Sequential INSERT (2 shards, 1000 rows) 4.22s 2000 rows deleted 'Parallel' INSERT (2 shards, 1000 rows) 1.98s 2000 rows deleted
> sapi/cli/php mysqli_poll_bulk_insert.php Sequential INSERT (2 shards, 1000 rows) 4.22s 2000 rows deleted 'Parallel' INSERT (2 shards, 1000 rows) 1.98s 2000 rows deleted Hi Ulf, I did a small modification to mysqlnd, locally,  that  enables it to send UPSERT queries in a batch, without reading the result from the query.  [...] Results are amazing (see total! -  ASYNC INSERTs take less than 60% of the SYNC , if not less ). You can show a slide tomorrow about it.  Andrey suffers from Insomnia
> sapi/cli/php mysqli_poll_bulk_insert.php Sequential INSERT (2 shards, 1000 rows) 4.22s 2000 rows deleted 'Parallel' INSERT (2 shards, 1000 rows) 1.98s 2000 rows deleted 100% experimental! Don't trust the performance figures! Andrey suffers from Insomnia II
Where to get mysqlnd with async? // the super secret Launchpad repository with all raw-bin ideas bzr clone lp:~andrey-mysql/php-mysqlnd/trunk/ // Get PHP 5.3 from cvs.php.net cd php5/ext rm -rf mysqli mysqlnd cp -R /path/to/bzr_clone/trunk/mysqlnd mysqlnd cp -R /path/to/bzr_clone/trunk/php5/ext/mysqli mysqli cd .. ./buildconf –-force ; ./configure -–with-mysqli=mysqlnd  make clean; make ,[object Object]
The End Feedback: ulf.wendel@sun.com The End Feedback: ulf.wendel@sun.com

More Related Content

What's hot

MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APIMTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
Six Apart KK
 
InnoDB Magic
InnoDB MagicInnoDB Magic
InnoDB Magic
sunnygleason
 
CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendCSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the Backend
FITC
 
Sequelize
SequelizeSequelize
Sequelize
Tarek Raihan
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
Stephan Hochdörfer
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
iKlaus
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
davidahaskins
 
Php Security - OWASP
Php  Security - OWASPPhp  Security - OWASP
Php Security - OWASP
Mizno Kruge
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
Nate Abele
 
Mobile Database Persistence
Mobile Database PersistenceMobile Database Persistence
Mobile Database Persistence
Eric Maxwell
 
Core (Data Model) of WordPress Core
Core (Data Model) of WordPress CoreCore (Data Model) of WordPress Core
Core (Data Model) of WordPress Core
Jake Goldman
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
Marcus Ramberg
 
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP TechnologyFnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
fntsofttech
 
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Cliff Seal
 
Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»
e-Legion
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP Applications
Pierre MARTIN
 
Recent Changes to jQuery's Internals
Recent Changes to jQuery's InternalsRecent Changes to jQuery's Internals
Recent Changes to jQuery's Internals
jeresig
 
Spine JS
Spine JSSpine JS
Spine JS
ambientphoto
 
Hacking Your Way To Better Security - php[tek] 2016
Hacking Your Way To Better Security - php[tek] 2016Hacking Your Way To Better Security - php[tek] 2016
Hacking Your Way To Better Security - php[tek] 2016
Colin O'Dell
 

What's hot (20)

MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APIMTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
 
InnoDB Magic
InnoDB MagicInnoDB Magic
InnoDB Magic
 
CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendCSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the Backend
 
Sequelize
SequelizeSequelize
Sequelize
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Php Security - OWASP
Php  Security - OWASPPhp  Security - OWASP
Php Security - OWASP
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
Mobile Database Persistence
Mobile Database PersistenceMobile Database Persistence
Mobile Database Persistence
 
Core (Data Model) of WordPress Core
Core (Data Model) of WordPress CoreCore (Data Model) of WordPress Core
Core (Data Model) of WordPress Core
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP TechnologyFnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
 
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
 
Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP Applications
 
Recent Changes to jQuery's Internals
Recent Changes to jQuery's InternalsRecent Changes to jQuery's Internals
Recent Changes to jQuery's Internals
 
Spine JS
Spine JSSpine JS
Spine JS
 
Hacking Your Way To Better Security - php[tek] 2016
Hacking Your Way To Better Security - php[tek] 2016Hacking Your Way To Better Security - php[tek] 2016
Hacking Your Way To Better Security - php[tek] 2016
 

Similar to Mysqlnd Async Ipc2008

20141011 mastering mysqlnd
20141011 mastering mysqlnd20141011 mastering mysqlnd
20141011 mastering mysqlnd
do_aki
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
Mariano Iglesias
 
Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)
Chris Barber
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
julien pauli
 
veracruz
veracruzveracruz
veracruz
tutorialsruby
 
veracruz
veracruzveracruz
veracruz
tutorialsruby
 
veracruz
veracruzveracruz
veracruz
tutorialsruby
 
veracruz
veracruzveracruz
veracruz
tutorialsruby
 
Understanding OpenStack Deployments - PuppetConf 2014
Understanding OpenStack Deployments - PuppetConf 2014Understanding OpenStack Deployments - PuppetConf 2014
Understanding OpenStack Deployments - PuppetConf 2014
Puppet
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)Sqli
Chema Alonso
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
Ulf Wendel
 
Apache spark core
Apache spark coreApache spark core
Apache spark core
Thành Nguyễn
 
Solving the Riddle of Search: Using Sphinx with Rails
Solving the Riddle of Search: Using Sphinx with RailsSolving the Riddle of Search: Using Sphinx with Rails
Solving the Riddle of Search: Using Sphinx with Rails
freelancing_god
 
OWASP PHPIDS talk slides
OWASP PHPIDS talk slidesOWASP PHPIDS talk slides
OWASP PHPIDS talk slides
guestd34230
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
Firdaus Adib
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
chartjes
 
Developing web applications in Rust
Developing web applications in RustDeveloping web applications in Rust
Developing web applications in Rust
Sylvain Wallez
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
Jesmar Cannao'
 

Similar to Mysqlnd Async Ipc2008 (20)

20141011 mastering mysqlnd
20141011 mastering mysqlnd20141011 mastering mysqlnd
20141011 mastering mysqlnd
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
 
Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)Intro to PECL/mysqlnd_ms (4/7/2011)
Intro to PECL/mysqlnd_ms (4/7/2011)
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
Understanding OpenStack Deployments - PuppetConf 2014
Understanding OpenStack Deployments - PuppetConf 2014Understanding OpenStack Deployments - PuppetConf 2014
Understanding OpenStack Deployments - PuppetConf 2014
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)Sqli
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Apache spark core
Apache spark coreApache spark core
Apache spark core
 
Solving the Riddle of Search: Using Sphinx with Rails
Solving the Riddle of Search: Using Sphinx with RailsSolving the Riddle of Search: Using Sphinx with Rails
Solving the Riddle of Search: Using Sphinx with Rails
 
OWASP PHPIDS talk slides
OWASP PHPIDS talk slidesOWASP PHPIDS talk slides
OWASP PHPIDS talk slides
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Developing web applications in Rust
Developing web applications in RustDeveloping web applications in Rust
Developing web applications in Rust
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
 

More from Ulf Wendel

MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group Replication
Ulf Wendel
 
HTTP Plugin for MySQL!
HTTP Plugin for MySQL!HTTP Plugin for MySQL!
HTTP Plugin for MySQL!
Ulf Wendel
 
Data massage: How databases have been scaled from one to one million nodes
Data massage: How databases have been scaled from one to one million nodesData massage: How databases have been scaled from one to one million nodes
Data massage: How databases have been scaled from one to one million nodes
Ulf Wendel
 
MySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspectiveMySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspective
Ulf Wendel
 
MySQL 5.7 Fabric: Introduction to High Availability and Sharding
MySQL 5.7 Fabric: Introduction to High Availability and Sharding MySQL 5.7 Fabric: Introduction to High Availability and Sharding
MySQL 5.7 Fabric: Introduction to High Availability and Sharding
Ulf Wendel
 
PoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HAPoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HA
Ulf Wendel
 
DIY: A distributed database cluster, or: MySQL Cluster
DIY: A distributed database cluster, or: MySQL ClusterDIY: A distributed database cluster, or: MySQL Cluster
DIY: A distributed database cluster, or: MySQL Cluster
Ulf Wendel
 
NoSQL in MySQL
NoSQL in MySQLNoSQL in MySQL
NoSQL in MySQL
Ulf Wendel
 
Vote NO for MySQL
Vote NO for MySQLVote NO for MySQL
Vote NO for MySQL
Ulf Wendel
 
PHP mysqlnd connection multiplexing plugin
PHP mysqlnd connection multiplexing pluginPHP mysqlnd connection multiplexing plugin
PHP mysqlnd connection multiplexing plugin
Ulf Wendel
 
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQLHTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
Ulf Wendel
 
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
Ulf Wendel
 
MySQL 5.6 Global Transaction IDs - Use case: (session) consistency
MySQL 5.6 Global Transaction IDs - Use case: (session) consistencyMySQL 5.6 Global Transaction IDs - Use case: (session) consistency
MySQL 5.6 Global Transaction IDs - Use case: (session) consistency
Ulf Wendel
 
MySQL 5.6 Global Transaction Identifier - Use case: Failover
MySQL 5.6 Global Transaction Identifier - Use case: FailoverMySQL 5.6 Global Transaction Identifier - Use case: Failover
MySQL 5.6 Global Transaction Identifier - Use case: Failover
Ulf Wendel
 
MySQL native driver for PHP (mysqlnd) - Introduction and overview, Edition 2011
MySQL native driver for PHP (mysqlnd) - Introduction and overview, Edition 2011MySQL native driver for PHP (mysqlnd) - Introduction and overview, Edition 2011
MySQL native driver for PHP (mysqlnd) - Introduction and overview, Edition 2011
Ulf Wendel
 
PHPopstar der PHP Unconference 2011
PHPopstar der PHP Unconference 2011PHPopstar der PHP Unconference 2011
PHPopstar der PHP Unconference 2011
Ulf Wendel
 
The mysqlnd replication and load balancing plugin
The mysqlnd replication and load balancing pluginThe mysqlnd replication and load balancing plugin
The mysqlnd replication and load balancing plugin
Ulf Wendel
 
Award-winning technology: Oxid loves the query cache
Award-winning technology: Oxid loves the query cacheAward-winning technology: Oxid loves the query cache
Award-winning technology: Oxid loves the query cache
Ulf Wendel
 
The power of mysqlnd plugins
The power of mysqlnd pluginsThe power of mysqlnd plugins
The power of mysqlnd plugins
Ulf Wendel
 
Mysqlnd query cache plugin benchmark report
Mysqlnd query cache plugin benchmark reportMysqlnd query cache plugin benchmark report
Mysqlnd query cache plugin benchmark report
Ulf Wendel
 

More from Ulf Wendel (20)

MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group Replication
 
HTTP Plugin for MySQL!
HTTP Plugin for MySQL!HTTP Plugin for MySQL!
HTTP Plugin for MySQL!
 
Data massage: How databases have been scaled from one to one million nodes
Data massage: How databases have been scaled from one to one million nodesData massage: How databases have been scaled from one to one million nodes
Data massage: How databases have been scaled from one to one million nodes
 
MySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspectiveMySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspective
 
MySQL 5.7 Fabric: Introduction to High Availability and Sharding
MySQL 5.7 Fabric: Introduction to High Availability and Sharding MySQL 5.7 Fabric: Introduction to High Availability and Sharding
MySQL 5.7 Fabric: Introduction to High Availability and Sharding
 
PoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HAPoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HA
 
DIY: A distributed database cluster, or: MySQL Cluster
DIY: A distributed database cluster, or: MySQL ClusterDIY: A distributed database cluster, or: MySQL Cluster
DIY: A distributed database cluster, or: MySQL Cluster
 
NoSQL in MySQL
NoSQL in MySQLNoSQL in MySQL
NoSQL in MySQL
 
Vote NO for MySQL
Vote NO for MySQLVote NO for MySQL
Vote NO for MySQL
 
PHP mysqlnd connection multiplexing plugin
PHP mysqlnd connection multiplexing pluginPHP mysqlnd connection multiplexing plugin
PHP mysqlnd connection multiplexing plugin
 
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQLHTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
 
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
 
MySQL 5.6 Global Transaction IDs - Use case: (session) consistency
MySQL 5.6 Global Transaction IDs - Use case: (session) consistencyMySQL 5.6 Global Transaction IDs - Use case: (session) consistency
MySQL 5.6 Global Transaction IDs - Use case: (session) consistency
 
MySQL 5.6 Global Transaction Identifier - Use case: Failover
MySQL 5.6 Global Transaction Identifier - Use case: FailoverMySQL 5.6 Global Transaction Identifier - Use case: Failover
MySQL 5.6 Global Transaction Identifier - Use case: Failover
 
MySQL native driver for PHP (mysqlnd) - Introduction and overview, Edition 2011
MySQL native driver for PHP (mysqlnd) - Introduction and overview, Edition 2011MySQL native driver for PHP (mysqlnd) - Introduction and overview, Edition 2011
MySQL native driver for PHP (mysqlnd) - Introduction and overview, Edition 2011
 
PHPopstar der PHP Unconference 2011
PHPopstar der PHP Unconference 2011PHPopstar der PHP Unconference 2011
PHPopstar der PHP Unconference 2011
 
The mysqlnd replication and load balancing plugin
The mysqlnd replication and load balancing pluginThe mysqlnd replication and load balancing plugin
The mysqlnd replication and load balancing plugin
 
Award-winning technology: Oxid loves the query cache
Award-winning technology: Oxid loves the query cacheAward-winning technology: Oxid loves the query cache
Award-winning technology: Oxid loves the query cache
 
The power of mysqlnd plugins
The power of mysqlnd pluginsThe power of mysqlnd plugins
The power of mysqlnd plugins
 
Mysqlnd query cache plugin benchmark report
Mysqlnd query cache plugin benchmark reportMysqlnd query cache plugin benchmark report
Mysqlnd query cache plugin benchmark report
 

Recently uploaded

PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
christinelarrosa
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
LizaNolte
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
UiPathCommunity
 
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
manji sharman06
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Ukraine
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's TipsGetting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
ScyllaDB
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
zjhamm304
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
Fwdays
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
DianaGray10
 

Recently uploaded (20)

PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
 
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's TipsGetting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
 

Mysqlnd Async Ipc2008

  • 1. Yes, its the mysqlnd talk!
  • 2.
  • 3. The MySQL PHP “Connectors” Andrey Hristov (Development - mysqlnd), Johannes Schlüter (Development), Ulf Wendel (QA) and Georg Richter (everything, somehow...)
  • 4. How PHP connects to MySQL PHP MySQL Server Library: implements MySQL Client-Server Protocol PHP API for PHP applications MySQL native driver for PHP / MySQL Client Library
  • 5.
  • 6. Inside PHP (on the C level!) PHP Extensions Zend Engine PDO ext/mysql ext/mysqli SAPI PDO_MYSQL PDO_XYZ MySQL Client Library (libmysql) or MySQL native driver for PHP (default as of PHP 5.3)
  • 7. PHP and the MySQL Client Library ext/mysql ext/mysqli PDO_MYSQL PHP Memory: emalloc, * PHP Infrastructure IO: PHP Streams MySQL Server MySQL Client Library Memory: malloc, * IO: read, write, ... Operating System
  • 8. PHP and mysqlnd ext/mysql ext/mysqli PDO_MYSQL PHP Memory: emalloc, * PHP Infrastruktor IO: PHP Streams mysqlnd - MySQL native driver for PHP (PHP 5.3+) MySQL Server
  • 9. Which API would you like?
  • 10.
  • 11.
  • 12. Read-Only Variablen (Copy on Write) <?php $row = mysqli_fetch_assoc($res); ?> MySQL Server 1M 1M 1M
  • 14.
  • 15. How to split and distribute? Postings Categories Users Single DB Postings, thread_id%2 = 0 Categories Users Shard 1 Postings, thread_id%2 = 1 Categories Users Shard 2 Categories Users Shard 1 Postings Shard 2 Categories Users Shard 1 Denormalized: Postings with users.nickname Shard 2
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Show all postings of a user $shard1 = mysqli_connect('shard1', ...); $res = $shard1->query('SELECT ... FROM users WHERE id = ...'); display_user($res); $res->free_result(); $shard1->close(); $shard2 = mysqli_connect('shard2', ...); $res = $shard2->query('SELECT ... FROM postings WHERE ...'); display_postings($res); $res->free_result(); $shard2->close(); $shard3 = mysqli_connect('shard3',...); $res = $shard3->query('SELECT ... FROM postings WHERE ...'); display_postings($res); $res->free_result(); $shard3->close();
  • 23. The basic idea PHP MySQL Server PHP MySQL Server PHP PHP PHP MySQL Server PHP MySQL Server PHP MySQL Server
  • 24. New asynchronous API boolean mysqli_query( string query, MYSQLI_ASYNC) int mysqli_poll( array $connections, array $except, array $rejected, int $tv_sec [, int tv_usec]) mixed mysqli_reap_async_query( mysqli $connection)
  • 25. Asynchronous “Show all ...” - I $shard1 = mysqli_connect('shard1', ...); $shard2 = mysqli_connect('shard2', ...); $shard3 = mysqli_connect('shard2', ...); $shard1->query('... FROM users ...', MYSQLI_ASYNC); $shard2->query('... FROM postings ...', MYSQLI_ASYNC); $shard3->query('... FROM postings ...', MYSQLI_ASYNC);
  • 26. Asynchronous “Show all ...” - II $all_links = array($shard1, $shard2, $shard3); $processed = 0; do { $links = $errors = $reject = array(); foreach ($all_links as $link) $links[] = $errors[] = $reject[] = $link; if (0 == ($ready = mysqli_poll($links, $errors, $reject, 1, 0)) continue; foreach ($links as $k => $link) { if ($res = mysqli_reap_async_query($link)) { mysqli_free_result($res); $processed++; } } } while ($processed < count($all_links));
  • 27.
  • 28. $start = microtime(true); $m1 = mysqli_connect('host', 'user', 'password', 'schema'); $m2 = mysqli_connect('host', 'user', 'password', 'schema'); mysqli_query($m1, 'SELECT SLEEP(0.10)', MYSQLI_ASYNC); mysqli_query($m2, 'SELECT SLEEP(0.25)', MYSQLI_ASYNC); printf(&quot;Query : %2.2fs&quot;, microtime(true) - $start); while ($processed < 2) { $links = array($m1, $m2); if (mysqli_poll($links, array(), array(), 0, 50000)) { foreach ($links as $k => $link) if ($res = mysqli_reap_async_query($link)) { mysqli_free_result($res); printf(&quot;Fetch %d : %2.2fs&quot;, ++$processed, microtime(true) - $start); } } printf(&quot;Poll : %2.2fs&quot;, microtime(true) - $start); } Is it faster? > sapi/cli/php mysqli_poll2.php Query : 0.00s Poll : 0.05s Fetch 1 : 0.11s Poll : 0.11s Poll : 0.15s Poll : 0.21s Fetch 2 : 0.26s Poll : 0.26s
  • 29. $m1 = mysqli_connect('host', 'user', 'passwd', 'database'); $m2 = mysqli_connect('host', 'user', 'passwd', 'database'); mysqli_query($m1, 'SELECT SLEEP(0.10)', MYSQLI_ASYNC); mysqli_query($m2, 'INSERT INTO users(id) VALUES (100)', MYSQLI_ASYNC); while ($processed < 2) { $links = array($m1, $m2); if (mysqli_poll($links, array(), array(), 0, 50000)) { foreach ($links as $link) if (is_object($res = mysqli_reap_async_query($link))) { $processed++; mysqli_free_result($res); } else { $processed++; } } } Mixing SELECT and INSERT > sapi/cli/php mysqli_poll2.php Query : 0.00s Poll : 0.05s Fetch 1 : 0.11s Poll : 0.11s Poll : 0.15s Poll : 0.21s Fetch 2 : 0.26s Poll : 0.26s
  • 30. $m1 = mysqli_connect('localhost', 'user', 'password', 'schema'); $m2 = mysqli_connect(&quot;localhost&quot;, &quot;user&quot;, &quot;password&quot;, &quot;schema&quot;); mysqli_query($m1, 'SELECT NIXNUTZ FOR PREDISENT', MYSQLI_ASYNC); mysqli_query($m2, &quot;SELECT 1&quot;, MYSQLI_ASYNC | MYSQLI_USE_RESULT); while ($processed < 2) { $links = array($m1, $m2); if (mysqli_poll($links, array(), array(), 0, 50000)) foreach ($links as $k => $link) { if (is_object($res = mysqli_reap_async_query($link))) { var_dump(mysqli_fetch_assoc($res)); mysqli_free_result($res); } else if (mysqli_errno($link)) printf(&quot;[%d] %s&quot;, mysqli_errno($link), mysqli_error($link)); else printf(&quot;no error, no result&quot;); $processed++; } } Handling Server errors > sapi/cli/php mysqli_poll_error.php array(1) { [1]=> string(1) &quot;1&quot; } [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PREDISENT' at line 1
  • 31. $m1 = mysqli_connect('host', 'user', 'password', 'schema'); $m2 = mysqli_connect('host', 'user', 'password', 'schema'); printf(&quot;Connection %d: no query&quot;, mysqli_thread_id($m1)); mysqli_query($m2, 'SELECT 1', MYSQLI_ASYNC | MYSQLI_USE_RESULT); printf(&quot;Connection %d: SELECT 1&quot;, mysqli_thread_id($m2)); while ($processed < 2) { $links = array($m1, $m2); $rejected = array($m1, $m2); if (0 == ($ready = mysqli_poll($links, array(), $rejected, 0, 50000))) continue; foreach ($rejected as $link) printf(&quot;Connection %d: rejected&quot;, mysqli_thread_id($link)); $processed += count($rejected); foreach ($links as $link) printf(&quot;Connection %d: accepted&quot;, mysqli_thread_id($link)); $processed += count($links); } Detecting invalid handles > sapi/cli/php mysqli_poll_invalid.php Connection 205: no query Connection 206: SELECT 1 Connection 205: rejected Connection 206: accepted
  • 32. if (mysqli_poll($links, array(), array(), 0, 5000)) foreach ($links as $link) { mysqli_reap_async_query($link); if (mysqli_errno($link)) die(mysqli_error($link)); $all_links[mysqli_thread_id($link)]['inserted']++; if ($all_links[mysqli_thread_id($link)]['inserted'] < $rows) { if (mysqli_query($link, $query, MYSQLI_ASYNC)) $i++; else die(mysqli_error($link)); } } Daily bulk INSERT - ./ me! (Part1) > sapi/cli/php mysqli_poll_bulk_insert.php Sequential INSERT (2 shards, 1000 rows) 4.22s 2000 rows deleted 'Parallel' INSERT (2 shards, 1000 rows) 1.98s 2000 rows deleted
  • 33. > sapi/cli/php mysqli_poll_bulk_insert.php Sequential INSERT (2 shards, 1000 rows) 4.22s 2000 rows deleted 'Parallel' INSERT (2 shards, 1000 rows) 1.98s 2000 rows deleted Hi Ulf, I did a small modification to mysqlnd, locally, that enables it to send UPSERT queries in a batch, without reading the result from the query. [...] Results are amazing (see total! - ASYNC INSERTs take less than 60% of the SYNC , if not less ). You can show a slide tomorrow about it. Andrey suffers from Insomnia
  • 34. > sapi/cli/php mysqli_poll_bulk_insert.php Sequential INSERT (2 shards, 1000 rows) 4.22s 2000 rows deleted 'Parallel' INSERT (2 shards, 1000 rows) 1.98s 2000 rows deleted 100% experimental! Don't trust the performance figures! Andrey suffers from Insomnia II
  • 35.
  • 36. The End Feedback: ulf.wendel@sun.com The End Feedback: ulf.wendel@sun.com