PHP mysqlnd connection multiplexing plugin
Upcoming SlideShare
Loading in...5
×
 

PHP mysqlnd connection multiplexing plugin

on

  • 2,937 Views

PECL/mysqlnd_mux adds multiplexing to all PHP MySQL APIs (mysql, mysqli, PDO_MySQL) compiled to use mysqlnd. Connection multiplexing refers to sharing one MySQL connection among multiple user ...

PECL/mysqlnd_mux adds multiplexing to all PHP MySQL APIs (mysql, mysqli, PDO_MySQL) compiled to use mysqlnd. Connection multiplexing refers to sharing one MySQL connection among multiple user connection handles, among multiple clients. Multiplexing does reduce client-side connection overhead and minimizes the total number of concurrently open connections. The latter lowers the MySQL server load. As a highly specific optimization it has not only strong but also weak sides. See, what this free plugin has to offer in prototype stage. And, how does it compare to other techniques such as pooling or persistent connections - what to use when tuning PHP MySQL to the extreme.

Statistics

Views

Total Views
2,937
Views on SlideShare
2,268
Embed Views
669

Actions

Likes
3
Downloads
34
Comments
0

13 Einbettungen 669

http://blog.ulf-wendel.de 624
http://localhost 10
http://www.ulf-wendel.de 9
http://blog.ulfwendel.de 6
http://www.twylah.com 6
http://feedreader.com 4
http://ulf-wendel.de 4
https://twitter.com 1
http://translate.googleusercontent.com 1
http://ulfwendel.de 1
http://www.shareist.com 1
http://twitter.com 1
https://twimg0-a.akamaihd.net 1
Mehr ...

Zugänglichkeit

Kategorien

Details hochladen

Uploaded via as OpenOffice

Benutzerrechte

© Alle Rechte vorbehalten

Report content

Als unangemessen gemeldet Als unangemessen melden
Als unangemessen melden

Wählen Sie Ihren Grund, warum Sie diese Präsentation als unangemessen melden.

Löschen
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Ihre Nachricht erscheint hier
    Processing...
Kommentar posten
Kommentar bearbeiten

PHP mysqlnd connection multiplexing plugin PHP mysqlnd connection multiplexing plugin Presentation Transcript

  • Ulf Wendel, Oracle PHP mysqlndConnection Multiplexing PECL/mysqlnd_mux 1.0.0-prototype
  • The speaker says...When fast is not fast enough, you pull all triggers. Thisincludes attempts to optimize an already reasonable fastoperation: connect time to MySQL.The PHP mysqlnd connection multiplexing plugin,shares a physical connection among multiple userhandles. Thus, connection overhead is saved on the clientside and the number of opened connection is reduced on theserver side.PECL/mysqlnd_mux is an Oracle open source developmentavailable from pecl.php.net. Developed by AndreyHristov.
  • Plugins are mostly transparent WordPress, Drupal, Symfony, Oxid, ZendFramework, ... mysql, mysqli, PDO_MYSQL mysqlnd PECL/mysqlnd_mux plugin Connection Multiplexing MySQL Server
  • The speaker says...PECL/mysqlnd_mux is a plugin for the mysqlnd library. Themysqlnd library is the default C client library usedby the PHP MySQL extensions mysql, mysqli andPDO_MySQL internally. Mysqlnd ships with PHP since 5.3.Plugins operate at a layer beneath the user APIs,thus improvements are available to all PHP MySQLAPIs.Other free plugins are PECL/mysqlnd_ms (replication andload balancing), PECL/mysqlnd_qc (client-side query cache)and many more.
  • PECL/mysqlnd_mux● Multiplexing: share connection among handles Reduce client connect overhead, reduce server load Prototype, requires PHP 5.5.0+ connect() connect() connect() n connection handles PECL/mysqlnd_mux 1 connection MySQL
  • The speaker says...The PHP mysqlnd connection multiplexing proxies MySQLconnections. Whenever a client attempts to open aconnection to a host, the plugin checks whether there isalready a cached network connection to the host inquestion. If not, a new connection is established andassociated with the users connection handle. Otherwise,the users connection handle is linked with analready opened network connection.This way, multiple user handles can point to thesame network connection and share it. Connectionoverhead is saved and fewer connections are opened.
  • The price you pay● Multiplexing means serializing tasks Possibility of wait situations Prototype: no upgrade to dedicated connection Prototype: no collision counter Query 1 MUX Query 1 Query 2 MySQL Query 2 Time
  • The speaker says...Sharing a resource often requires serializing access to it.This is also the case with a shared connection of the PHPmysqlnd connection multiplexing plugin. Serializingactions bares the risks of collisions and waitsituations. In the example, a clients query has to wait forcompletion of another clients query before it can beexecuted. Query 2 waits for query 1 to finish.The prototype is using a mutex to synchronize access to ashared connection.
  • MUX as a demo of the plugin API● No new API calls, it just works! Supports popular buffered queries (mysql_query(), mysqli_query(), PDO if using PDO::ATTR_EMULATE_PREPARES) Prototype does not handle unbuffered queries (mysqli_real_query()) Prepared statements not in 1.0.0-prototype (mysqli_stmt_*())
  • The speaker says...PECL/mysqlnd_mux 1.0.0-prototype is an example of thestrenghts of the mysqlnd C plugin API. The initial publicrelease is not a production-ready stable solution. Featureshave been skipped for the prototype to keep thedemo of the plugin API short and comprehensive.The astonishing finding of the plugin is that multiplexingcan be added to add PHP MySQL APIs withoutchanging the APIs. It just works – for some cases alreadytoday. Other cases could be covered in futureversions, depending on user feedback.
  • THATS IT FOLKS?
  • Compared to pooling● Connection remains open after close() Connection establishment overhead reduced Number of concurrent connections not reduced Usually, connection state reset upon reuse Client Client Connection pool Connection Connection Connection MySQL
  • The speaker says...A connection pool is a cache for connections. If aclient openes a connection, the pool is checked for analready estiablished connection to the requested host. Incase of a hit, the pooled connection is reset, then taken fromthe pool of unused connections and returned to the client. Ifno connection is found a new one gets opened and returnedto the caller. Then, the connection is used until the clientcalls close(). Upon close(), the connection is not closed butput back into the pool for reuse.Pooling saves time on reuse but does not reduce the totalnumber of concurrent connections.
  • Persistent Connection● Connection remains open after close() Connection overhead and reuse costs reduced Number of concurrent connections not reduced Connection state not reset before reuse Client 1 Pool Connection 1 MySQL SET @myvar = 1 Client 2 Pool Connection 1 MySQL SELECT @myvar
  • The speaker says...Persistent connections can be described as a special kind of pooled connections. As the name says, the state of apersistent connection is not reset between use .PHP persistent database connections have often beencriticised for persisting the state of a connection... - for theirvery purpose!Thus, when „persistent connections“ have been added to themysqli extension, mysqli actually got pooledconnections. By default, the connection state isreset before reuse. Performance fanatics can disable thisduring compile time.
  • Speed-up tricks compared● Every optimization is a trade You gain something: fewer connections opened You give something: collision possible You gain something: lower connection costs You give something: no isolation of connection state MUX Pooled Pers. Conn Conn.Reduce connection overhead Yes Yes YesReduce # concurrently open connections Yes No NoConnection state shared among clients Yes No Yes (mysqli: No)Serialization required, collisions possible Yes No No
  • The speaker says...Optimizations, such as multiplexing, pooling or persistentconnections come at a price. There is no one-fits all trick.Please, try to understand the properties of eachoption. Then, decide on a case-by-case basiswhich technology to use.
  • Remember: scope/life-span● Pools are bound to a PHP process Depending on deployment model, a PHP process handles one or multiple requests HTTP Server PHP process PHP process Connection pool Connection pool Conn 1 Conn 2 Conn 3 Conn 4
  • The speaker says...Operating systems associate file descriptors, includingnetwork connections, with processes. At the end of theprocess, the network connections are closed. Thus, thelife-span of every client-side cache/pool of a PHPprocess is that of the PHP process. No matterwhether we are discussing connections cached formultiplexing or persistent connections as found inany of the PHP MySQL APIs (mysql, mysqli,PDO_MySQL).Depending on the web server deployment model, a PHPprocess handles one or multiple requests (script runs).
  • THE END http://www.slideshare.net/nixnutz/Contact: ulf.wendel@oracle.com, @Ulf_Wendel