PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

PECL/mysqlnd_*: CCC - cloud, cluster, caching!

Note: This article was originally published at Planet PHP on 12 January 2012.
Planet PHP

We are giving PECL/mysqlnd_qc a second chance. PECL/mysqlnd_qc is a query cache plugin for mysqlnd. It can cache any query issued by any PHP MySQL extension using storage handler for process memory, APC, Memcache and SQLlite. Its default invalidation strategy is Time to Live (TTL). Using a more sophisticated invalidation strategy is possible. Of course, its transparent to use and inherits all the other advantages of a driver based approach.

Award-winning technology: Oxid loves the query cache
View more presentations on PHP and MySQL

Cloud and Cluster

Albeit quite powerful the plugin came late and is faced with stiff competition from application-based solutions. With everybody talking about cloud and database clusters, there is a new use case for client-side caching.

No all-in-one cluster solution for all purposes exsits. MySQL users, for example, can choose between MySQL Replication, MySQL Cluster and an emerging number of third party solutions, which proof MySQL to be alive and rocking. The CAP theorem makes me assume that MySQL users will continue to have multiple choices.

Whatever cluster solution will become the dominating force, applications should be enabled to see a cluster as a service. Accordingly, PECL/mysqlnd_ms 1.2 has introduced an API to set the required service level. In version 1.2 the service level option focusses on consistency:

  • Eventual consistency - stale data allows, e.g. when reading from a MySQL replication slave
  • Session consistency - read your writes
  • Strong consistency - every client sees all writes

Whatever type of cluster is used, PECL/mysqlnd_ms will try to deliver the requested consistency by selecting appropriate nodes.

Caching

If the application hints the database driver that eventual consistency is sufficient but data returned shall not be more than five seconds behind, the database driver can replace a slow, eventually remote database access with a fast, local cache access. That's the second chance PECL/mysqlnd_qc will be given.

PHP application Service level: eventual consistency, max 5 seconds old Any PHP MySQL extension (mysqli, PDO_MySQL, mysql) mysqlnd library PECL/mysqlnd_ms - PECL/mysqlnd_qc A A | or | A A Process memory, Memcache, a A | A A A A MySQL

Documentation updates

Before we begin with it, I have given the PECL/mysqlnd_qc a second chance as well. You can expect to find an improved Quickstart and Examples section at http://docs.php.net/manual/en/book.mysqlnd-qc.php soon. Have a look during the next days, its a cool plugin thing even without the cloud buzzword bingoa

Happy New Year and happy hacking!

@Ulf_Wendel

PHP 5.4 and APC notes

PECL/mysqlnd_qc 1.0.1 is not compatible with PHP 5.4. It has not been updated to the latest mysqlnd API as found in PHP 5.4. Andrey and I have prepared a patch and hope to push a 1.0.2 release soon. Unfortunately, the (private) C API of APC has also changed in the past year. Thus, the cache cannot use a recent APC version for storing cache entries. Of course, you can still use the latest version of APC to boost your PHP scripts even if the scripts use the query cache plugin.