SlideShare a Scribd company logo
1 of 36
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 APISix Apart KK
 
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 BackendFITC
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmdiKlaus
 
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 2011Masahiro Nagano
 
Php Security - OWASP
Php  Security - OWASPPhp  Security - OWASP
Php Security - OWASPMizno 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 FrameworksNate Abele
 
Mobile Database Persistence
Mobile Database PersistenceMobile Database Persistence
Mobile Database PersistenceEric Maxwell
 
Core (Data Model) of WordPress Core
Core (Data Model) of WordPress CoreCore (Data Model) of WordPress Core
Core (Data Model) of WordPress CoreJake Goldman
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From IusethisMarcus 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 Technologyfntsofttech
 
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 2014Cliff Seal
 
Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»e-Legion
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsPierre MARTIN
 
Recent Changes to jQuery's Internals
Recent Changes to jQuery's InternalsRecent Changes to jQuery's Internals
Recent Changes to jQuery's Internalsjeresig
 
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] 2016Colin 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 mysqlnddo_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 CakePHPMariano 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 BeginnersPriti Solanki
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionjulien pauli
 
Understanding OpenStack Deployments - PuppetConf 2014
Understanding OpenStack Deployments - PuppetConf 2014Understanding OpenStack Deployments - PuppetConf 2014
Understanding OpenStack Deployments - PuppetConf 2014Puppet
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)SqliChema 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/APIsUlf Wendel
 
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 Railsfreelancing_god
 
OWASP PHPIDS talk slides
OWASP PHPIDS talk slidesOWASP PHPIDS talk slides
OWASP PHPIDS talk slidesguestd34230
 
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 IIFirdaus Adib
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Developing web applications in Rust
Developing web applications in RustDeveloping web applications in Rust
Developing web applications in RustSylvain Wallez
 
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.pdfJesmar 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 ReplicationUlf 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 nodesUlf 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 perspectiveUlf 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 HAUlf 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 ClusterUlf Wendel
 
NoSQL in MySQL
NoSQL in MySQLNoSQL in MySQL
NoSQL in MySQLUlf Wendel
 
Vote NO for MySQL
Vote NO for MySQLVote NO for MySQL
Vote NO for MySQLUlf Wendel
 
PHP mysqlnd connection multiplexing plugin
PHP mysqlnd connection multiplexing pluginPHP mysqlnd connection multiplexing plugin
PHP mysqlnd connection multiplexing pluginUlf 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 MySQLUlf 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.4Ulf 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) consistencyUlf 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: FailoverUlf 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 2011Ulf Wendel
 
PHPopstar der PHP Unconference 2011
PHPopstar der PHP Unconference 2011PHPopstar der PHP Unconference 2011
PHPopstar der PHP Unconference 2011Ulf 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 pluginUlf 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 cacheUlf Wendel
 
The power of mysqlnd plugins
The power of mysqlnd pluginsThe power of mysqlnd plugins
The power of mysqlnd pluginsUlf Wendel
 
Mysqlnd query cache plugin benchmark report
Mysqlnd query cache plugin benchmark reportMysqlnd query cache plugin benchmark report
Mysqlnd query cache plugin benchmark reportUlf 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

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

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