SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
<Insert Picture Here>
MySQL Client Side Caching
Johannes Schlüter
Twitter: @phperror
MySQL Engineering – Connectors and Client Connectivity
# pecl install mysqlnd_qc-beta
Gracias por vuestra atención!
mysqlnd
Server API (SAPI)
CGI CLI Embed ISAPI NSAPI phttpd thttpd ...
Zend Engine PHP Runtime
PHP Extensions
bcmath mysql mysqli mysqlnd pdo pdo_mysql xml ...
PHP 5.3 and mysqlndPHP
PHPMemory
PHPStreams
Infrastructure
mysqlnd – MySQL native driver for PHP
MySQL Server
ext/mysql mysqli PDO_mysql
…
PHP Module (Extension) API
Building PHP with mysqlnd
• ./configure 
--with-mysql=mysqlnd 
--with-mysqli=msqlnd 
--with-pdo-mysql=mysqlnd
• Default on Windows and some distributions
mysqlnd vs. libmysql
MySQL Server MySQL Server
mysqlnd libmysql
PHP PHP
PHP Memory
libmysql Memory
PHP Memory
PHP Memory
copy
copy
usedirectly
copy
mysqlnd Statistics
• Around 150 statistic values collected
• mysqli_get_client_stats (),
mysqli_get_connection_stats()
Asynchronous Queries
/* Do something */
PHP Script MySQL
query
result
query
poll
result
$conn = new MySQLi(...);
$conn->query(
"SELECT * FROM t WHERE ....",
MYSQLI_ASYNC);
/* Process query results */
mysqli_poll($links, $errors, $reject, 1);
Sharding
<?php
…
?>
Sharding
foreach ($all_links as $link)
$link->query("SELECT 'test' ", MYSQLI_ASYNC);
$processed = 0;
do {
$links = $all_links;
if (!mysqli_poll($links, $errors, $reject, 1)) continue; /* TIMEOUT */
foreach ($links as $link) {
if ($result = $link->reap_async_query()) {
print_r($result->fetch_row());
mysqli_free_result($result);
$processed++;
}
}
} while ($processed < count($all_links));
mysqlnd plugins
Plugin Hook
mysqlnd Query
mysqli::query()mysql_query() PDO::query()
Wire Protocol
Plugin Hook
Network
Drupal, Symphony, phpMyFAQ, phpMyAdmin, Oxid, ...
ext/mysql, ext/mysqli, ext/PDO_MYSQL
MySQL Server
mysqlnd
Load Balancing Monitoring Performance
mysqlnd plugin
Query Cache Plugin vs. MySQL Proxy
Application client Application client Application client
MySQL Proxy
PHP client PHP client PHP client
mysqlnd pluginmysqlnd plugin mysqlnd plugin
MySQL Server
MySQL Server
Experimental Extensions
• By Oracle:
– mysqlnd_sip
– mysqlnd_mc
– mysqlnd_ms
– mysqlnd_pscache
• By Community:
– mysqlnd_uh
(David Soria Parra /
Mayflower GmbH)
• http://pecl.php.net/
The Database Is The Bottleneck
Caching!
“Traditional” Caches
• MySQL Server Cache
– MySQL Query Cache
• Application-Level Cache
– PEAR::Cache, Zend_Cache, …
MySQL Query Cache (Server-Side)
✔
Integrated with the MySQL Server
✔
No application changes
✔
Automatic invalidation
–
table based
✗
Needs network communication with server
✗
Needs server resources (memory, CPU)
Application-Level Caches
✔
Can cache higher level structures
– Complete rendered HTML blocks
✔
Multiple backends
– Can be shared over multiple servers (via memcache etc.)
✗
No automatic invalidation
✗
Requires application changes
<Insert Picture Here>
Introducing:
mysqlnd Client Side Cache
# pecl install mysqlnd_qc-beta
Andrey Hristov
Ulf Wendel
mysqlnd Query Cache
PHP
mysql / mysqli / PDO_mysql
mysqlnd
Cache Backend
Query Cache
MySQL Server
SELECT a
FROM t No!
SELECT a
FROM t
ResultResult
Local Memory, APC,
Memcache, Custom Handler
Key Properties
• Transparent
– PHP Extension hooking into mysqlnd
• Works with ext/mysql, mysqli, pdo_mysql
• Pluggable storage handler
– By default: local memory, APC, memcache, SQLite
– PHP Userspace
• Invalidation via TTL
– No automatic invalidation by server
– Custom handlers may use custom invalidation logic
Transparent?
$mysqli = new mysqli($host, $user, $pw, $db);
$sql = “SELECT SLEEP(10) FROM table”;
$start = microtime(true);
$res = $mysqli->query($sql);
$res = $mysqli->query($sql);
$end = microtime(true);
echo $end - $start;
→ 20.019539117813
Transparent?
$mysqli = new mysqli($host, $user, $pw, $db);
$sql = sprintf(“/*%s*/SELECT SLEEP(10) FROM table”,
MYSQLND_QC_ENABLE_SWITCH);
$start = microtime(true);
$res = $mysqli->query($sql);
$res = $mysqli->query($sql);
$end = microtime(true);
echo $end - $start;
→ 10.142804088593
Transparent!
mysqlnd_qc.cache_by_default = 1
!Usually you should NOT do this!
SQL Hints
• MYSQLND_QC_ENABLE_SWITCH
– qc=on
• MYSQLND_QC_DISABLE_SWITCH
– qc=off
• MYSQLND_QC_TTL_SWITCH
– qc_ttl=
Storage Handlers
●
Storage
– Scope: request, process, machine, multi-machine
– Location: distance to cache
– Replacement strategy
– Slam defense strategy
●
Decide what to cache
– is_select() - detect SQL hints
●
Extended statistics
– Storage statistics, traces, timings
Cache Expiry
Client 1
MySQL
Client 2...n
Cache Hit
MySQL
Client 1 Client 2...n
Slam Defense
Client 1
MySQL
Client 2...n
Expired
MySQL
Client 1 Client 2...n
Cache Hit
Refresh
Core Statistics
• Collected by: mysqlnd_qc core
– php.net/manual/en/function.mysqlnd_qc_get_core_stats.php
• Scope: process
– Process: mysqlnd_qc_get_core_stats()
– Aggregated values from all PHP MySQL APIs
• Contents: wide range
– Cache usage and efficiency
– Network related
– Timings
Query Statistics and Backtraces
• Collected by: mysqlnd_qc core
– php.net/manual/en/function.mysqlnd_qc_get_query_trace_log
.php
• Scope: process
– mysqlnd_qc_get_query_trace_log()
– mysqlnd_qc_get_normalized_query_trace_log()
• Contents
– Origin - backtrace
– Timings
Storage Handler Statistics
• Collected by: storage handler
– php.net/manual/en/function..mysqlnd_qc_get_cache_info.php
• Scope: cache entry
– Depends on storage handler scope
– Aggregated values from all PHP MySQL APIs
• Contents: none or assorted
– Depends on storage handler support
– APC: timings, hit ratio, result set size
– Default: APC plus result set meta data
User-Defined Storage Handler
• Procedural
– php.net/manual/en/function.mysqlnd_qc_set_user_handlers.php
– Callback functions
• Object oriented
– slideshare.net/nixnutz/mysqlnd-query-cache-plugin-userdefined-
storage-handler
– Interface mysqlnd_qc_handler
• Extending mysqlnd_qc_handler_default
<?php
/* auto_prepend_file = /path/to/prepend.php */
class my_qc extends mysqlnd_qc_handler_default
{
public function is_select($query)
{
if (preg_match("@from employees where@ism", $query))
{
/* cache query for mysqlnd_qc.ttl seconds */
return true;
}
return parent::is_select($query);
}
}
$qc = new my_qc();
mysqlnd_qc_change_handler($qc);
?>
Resources
• php.net/mysqlnd_qc
– Installation, Examples, Functions
• php.net/mysqlnd
– Introduction, Changes, C plugin API
• slideshare.net/nixnutz/presentations
– QC Basics
– QC User defined storage handler
– QC Statistics
– QC Benchmark impressions
The preceding is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into any
contract. It is not a commitment to deliver any
material, code, or functionality, and should not be
relied upon in making purchasing decisions.
The development, release, and timing of any
features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.
Barcelona mysqlnd qc
Barcelona mysqlnd qc

Más contenido relacionado

La actualidad más candente

Evolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best PracticesEvolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best PracticesMydbops
 
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...Tim Vaillancourt
 
Drupal performance optimization Best Practices
Drupal performance optimization Best PracticesDrupal performance optimization Best Practices
Drupal performance optimization Best PracticesRatnesh kumar, CSM
 
Memcached Presentation
Memcached PresentationMemcached Presentation
Memcached PresentationAsif Ali
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016Derek Downey
 
Security features In MySQL 8.0
Security features In MySQL 8.0Security features In MySQL 8.0
Security features In MySQL 8.0Mydbops
 
CHI - YAPC NA 2012
CHI - YAPC NA 2012CHI - YAPC NA 2012
CHI - YAPC NA 2012jonswar
 
Wordpress optimization
Wordpress optimizationWordpress optimization
Wordpress optimizationAlmog Baku
 
Using memcache to improve php performance
Using memcache to improve php performanceUsing memcache to improve php performance
Using memcache to improve php performanceSudar Muthu
 
Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)WordCamp Cape Town
 
Load Balancing with Nginx
Load Balancing with NginxLoad Balancing with Nginx
Load Balancing with NginxMarian Marinov
 
Boost your website by running PHP on Nginx
Boost your website by running PHP on NginxBoost your website by running PHP on Nginx
Boost your website by running PHP on NginxHarald Zeitlhofer
 
CHI-YAPC-2009
CHI-YAPC-2009CHI-YAPC-2009
CHI-YAPC-2009jonswar
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQLMydbops
 
ProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLRené Cannaò
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cacheMarc Cortinas Val
 
MyDUMPER : Faster logical backups and restores
MyDUMPER : Faster logical backups and restores MyDUMPER : Faster logical backups and restores
MyDUMPER : Faster logical backups and restores Mydbops
 
Building low latency java applications with ehcache
Building low latency java applications with ehcacheBuilding low latency java applications with ehcache
Building low latency java applications with ehcacheChris Westin
 

La actualidad más candente (19)

Evolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best PracticesEvolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best Practices
 
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
 
Drupal performance optimization Best Practices
Drupal performance optimization Best PracticesDrupal performance optimization Best Practices
Drupal performance optimization Best Practices
 
Memcached Presentation
Memcached PresentationMemcached Presentation
Memcached Presentation
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016
 
Security features In MySQL 8.0
Security features In MySQL 8.0Security features In MySQL 8.0
Security features In MySQL 8.0
 
CHI - YAPC NA 2012
CHI - YAPC NA 2012CHI - YAPC NA 2012
CHI - YAPC NA 2012
 
Wordpress optimization
Wordpress optimizationWordpress optimization
Wordpress optimization
 
Using memcache to improve php performance
Using memcache to improve php performanceUsing memcache to improve php performance
Using memcache to improve php performance
 
Memcached
MemcachedMemcached
Memcached
 
Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)
 
Load Balancing with Nginx
Load Balancing with NginxLoad Balancing with Nginx
Load Balancing with Nginx
 
Boost your website by running PHP on Nginx
Boost your website by running PHP on NginxBoost your website by running PHP on Nginx
Boost your website by running PHP on Nginx
 
CHI-YAPC-2009
CHI-YAPC-2009CHI-YAPC-2009
CHI-YAPC-2009
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQL
 
ProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQL
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
MyDUMPER : Faster logical backups and restores
MyDUMPER : Faster logical backups and restores MyDUMPER : Faster logical backups and restores
MyDUMPER : Faster logical backups and restores
 
Building low latency java applications with ehcache
Building low latency java applications with ehcacheBuilding low latency java applications with ehcache
Building low latency java applications with ehcache
 

Similar a Barcelona mysqlnd qc

MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
 MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013   MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013 Serge Frezefond
 
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
 
Speeding Up The Snail
Speeding Up The SnailSpeeding Up The Snail
Speeding Up The SnailMarcus Deglos
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionjulien pauli
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Wim Godden
 
PHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on NginxPHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on NginxHarald Zeitlhofer
 
Mysqlnd query cache plugin statistics and tuning
Mysqlnd query cache plugin statistics and tuningMysqlnd query cache plugin statistics and tuning
Mysqlnd query cache plugin statistics and tuningUlf Wendel
 
php & performance
 php & performance php & performance
php & performancesimon8410
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance毅 吕
 
Deploying nginx with minimal system resources
Deploying nginx with minimal system resourcesDeploying nginx with minimal system resources
Deploying nginx with minimal system resourcesMax Ukhanov
 
Improve WordPress performance with caching and deferred execution of code
Improve WordPress performance with caching and deferred execution of codeImprove WordPress performance with caching and deferred execution of code
Improve WordPress performance with caching and deferred execution of codeDanilo Ercoli
 
HPPG - high performance photo gallery
HPPG - high performance photo galleryHPPG - high performance photo gallery
HPPG - high performance photo galleryRemigijus Kiminas
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magentoMathew Beane
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHPJonathan Klein
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 

Similar a Barcelona mysqlnd qc (20)

MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
 MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013   MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
 
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
 
Speeding Up The Snail
Speeding Up The SnailSpeeding Up The Snail
Speeding Up The Snail
 
Ipc mysql php
Ipc mysql php Ipc mysql php
Ipc mysql php
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
 
PHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on NginxPHP conference Berlin 2015: running PHP on Nginx
PHP conference Berlin 2015: running PHP on Nginx
 
Mysqlnd query cache plugin statistics and tuning
Mysqlnd query cache plugin statistics and tuningMysqlnd query cache plugin statistics and tuning
Mysqlnd query cache plugin statistics and tuning
 
php & performance
 php & performance php & performance
php & performance
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Deploying nginx with minimal system resources
Deploying nginx with minimal system resourcesDeploying nginx with minimal system resources
Deploying nginx with minimal system resources
 
Improve WordPress performance with caching and deferred execution of code
Improve WordPress performance with caching and deferred execution of codeImprove WordPress performance with caching and deferred execution of code
Improve WordPress performance with caching and deferred execution of code
 
Wckansai 2014
Wckansai 2014Wckansai 2014
Wckansai 2014
 
HPPG - high performance photo gallery
HPPG - high performance photo galleryHPPG - high performance photo gallery
HPPG - high performance photo gallery
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 

Más de Anis Berejeb

Advanced Date/Time Handling with PHP
Advanced Date/Time Handling with PHPAdvanced Date/Time Handling with PHP
Advanced Date/Time Handling with PHPAnis Berejeb
 
APC & Memcache the High Performance Duo
APC & Memcache the High Performance DuoAPC & Memcache the High Performance Duo
APC & Memcache the High Performance DuoAnis Berejeb
 
Mysqlnd Query Cache
Mysqlnd Query CacheMysqlnd Query Cache
Mysqlnd Query CacheAnis Berejeb
 
Barcelona 2010 hidden_features
Barcelona 2010 hidden_featuresBarcelona 2010 hidden_features
Barcelona 2010 hidden_featuresAnis Berejeb
 

Más de Anis Berejeb (8)

Perf tuning2
Perf tuning2Perf tuning2
Perf tuning2
 
Explain2
Explain2Explain2
Explain2
 
Advanced Date/Time Handling with PHP
Advanced Date/Time Handling with PHPAdvanced Date/Time Handling with PHP
Advanced Date/Time Handling with PHP
 
APC & Memcache the High Performance Duo
APC & Memcache the High Performance DuoAPC & Memcache the High Performance Duo
APC & Memcache the High Performance Duo
 
Mysqlnd Query Cache
Mysqlnd Query CacheMysqlnd Query Cache
Mysqlnd Query Cache
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
Barcelona 2010 hidden_features
Barcelona 2010 hidden_featuresBarcelona 2010 hidden_features
Barcelona 2010 hidden_features
 

Último

Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 

Último (20)

Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

Barcelona mysqlnd qc

  • 1.
  • 2. <Insert Picture Here> MySQL Client Side Caching Johannes Schlüter Twitter: @phperror MySQL Engineering – Connectors and Client Connectivity
  • 3. # pecl install mysqlnd_qc-beta
  • 4. Gracias por vuestra atención!
  • 5. mysqlnd Server API (SAPI) CGI CLI Embed ISAPI NSAPI phttpd thttpd ... Zend Engine PHP Runtime PHP Extensions bcmath mysql mysqli mysqlnd pdo pdo_mysql xml ...
  • 6. PHP 5.3 and mysqlndPHP PHPMemory PHPStreams Infrastructure mysqlnd – MySQL native driver for PHP MySQL Server ext/mysql mysqli PDO_mysql … PHP Module (Extension) API
  • 7. Building PHP with mysqlnd • ./configure --with-mysql=mysqlnd --with-mysqli=msqlnd --with-pdo-mysql=mysqlnd • Default on Windows and some distributions
  • 8. mysqlnd vs. libmysql MySQL Server MySQL Server mysqlnd libmysql PHP PHP PHP Memory libmysql Memory PHP Memory PHP Memory copy copy usedirectly copy
  • 9. mysqlnd Statistics • Around 150 statistic values collected • mysqli_get_client_stats (), mysqli_get_connection_stats()
  • 10. Asynchronous Queries /* Do something */ PHP Script MySQL query result query poll result $conn = new MySQLi(...); $conn->query( "SELECT * FROM t WHERE ....", MYSQLI_ASYNC); /* Process query results */ mysqli_poll($links, $errors, $reject, 1);
  • 12. Sharding foreach ($all_links as $link) $link->query("SELECT 'test' ", MYSQLI_ASYNC); $processed = 0; do { $links = $all_links; if (!mysqli_poll($links, $errors, $reject, 1)) continue; /* TIMEOUT */ foreach ($links as $link) { if ($result = $link->reap_async_query()) { print_r($result->fetch_row()); mysqli_free_result($result); $processed++; } } } while ($processed < count($all_links));
  • 13. mysqlnd plugins Plugin Hook mysqlnd Query mysqli::query()mysql_query() PDO::query() Wire Protocol Plugin Hook Network
  • 14. Drupal, Symphony, phpMyFAQ, phpMyAdmin, Oxid, ... ext/mysql, ext/mysqli, ext/PDO_MYSQL MySQL Server mysqlnd Load Balancing Monitoring Performance mysqlnd plugin
  • 15. Query Cache Plugin vs. MySQL Proxy Application client Application client Application client MySQL Proxy PHP client PHP client PHP client mysqlnd pluginmysqlnd plugin mysqlnd plugin MySQL Server MySQL Server
  • 16. Experimental Extensions • By Oracle: – mysqlnd_sip – mysqlnd_mc – mysqlnd_ms – mysqlnd_pscache • By Community: – mysqlnd_uh (David Soria Parra / Mayflower GmbH) • http://pecl.php.net/
  • 17. The Database Is The Bottleneck
  • 19. “Traditional” Caches • MySQL Server Cache – MySQL Query Cache • Application-Level Cache – PEAR::Cache, Zend_Cache, …
  • 20. MySQL Query Cache (Server-Side) ✔ Integrated with the MySQL Server ✔ No application changes ✔ Automatic invalidation – table based ✗ Needs network communication with server ✗ Needs server resources (memory, CPU)
  • 21. Application-Level Caches ✔ Can cache higher level structures – Complete rendered HTML blocks ✔ Multiple backends – Can be shared over multiple servers (via memcache etc.) ✗ No automatic invalidation ✗ Requires application changes
  • 23. # pecl install mysqlnd_qc-beta Andrey Hristov Ulf Wendel
  • 24. mysqlnd Query Cache PHP mysql / mysqli / PDO_mysql mysqlnd Cache Backend Query Cache MySQL Server SELECT a FROM t No! SELECT a FROM t ResultResult Local Memory, APC, Memcache, Custom Handler
  • 25. Key Properties • Transparent – PHP Extension hooking into mysqlnd • Works with ext/mysql, mysqli, pdo_mysql • Pluggable storage handler – By default: local memory, APC, memcache, SQLite – PHP Userspace • Invalidation via TTL – No automatic invalidation by server – Custom handlers may use custom invalidation logic
  • 26. Transparent? $mysqli = new mysqli($host, $user, $pw, $db); $sql = “SELECT SLEEP(10) FROM table”; $start = microtime(true); $res = $mysqli->query($sql); $res = $mysqli->query($sql); $end = microtime(true); echo $end - $start; → 20.019539117813
  • 27. Transparent? $mysqli = new mysqli($host, $user, $pw, $db); $sql = sprintf(“/*%s*/SELECT SLEEP(10) FROM table”, MYSQLND_QC_ENABLE_SWITCH); $start = microtime(true); $res = $mysqli->query($sql); $res = $mysqli->query($sql); $end = microtime(true); echo $end - $start; → 10.142804088593
  • 29. SQL Hints • MYSQLND_QC_ENABLE_SWITCH – qc=on • MYSQLND_QC_DISABLE_SWITCH – qc=off • MYSQLND_QC_TTL_SWITCH – qc_ttl=
  • 30. Storage Handlers ● Storage – Scope: request, process, machine, multi-machine – Location: distance to cache – Replacement strategy – Slam defense strategy ● Decide what to cache – is_select() - detect SQL hints ● Extended statistics – Storage statistics, traces, timings
  • 31. Cache Expiry Client 1 MySQL Client 2...n Cache Hit MySQL Client 1 Client 2...n
  • 32. Slam Defense Client 1 MySQL Client 2...n Expired MySQL Client 1 Client 2...n Cache Hit Refresh
  • 33. Core Statistics • Collected by: mysqlnd_qc core – php.net/manual/en/function.mysqlnd_qc_get_core_stats.php • Scope: process – Process: mysqlnd_qc_get_core_stats() – Aggregated values from all PHP MySQL APIs • Contents: wide range – Cache usage and efficiency – Network related – Timings
  • 34. Query Statistics and Backtraces • Collected by: mysqlnd_qc core – php.net/manual/en/function.mysqlnd_qc_get_query_trace_log .php • Scope: process – mysqlnd_qc_get_query_trace_log() – mysqlnd_qc_get_normalized_query_trace_log() • Contents – Origin - backtrace – Timings
  • 35. Storage Handler Statistics • Collected by: storage handler – php.net/manual/en/function..mysqlnd_qc_get_cache_info.php • Scope: cache entry – Depends on storage handler scope – Aggregated values from all PHP MySQL APIs • Contents: none or assorted – Depends on storage handler support – APC: timings, hit ratio, result set size – Default: APC plus result set meta data
  • 36. User-Defined Storage Handler • Procedural – php.net/manual/en/function.mysqlnd_qc_set_user_handlers.php – Callback functions • Object oriented – slideshare.net/nixnutz/mysqlnd-query-cache-plugin-userdefined- storage-handler – Interface mysqlnd_qc_handler • Extending mysqlnd_qc_handler_default
  • 37. <?php /* auto_prepend_file = /path/to/prepend.php */ class my_qc extends mysqlnd_qc_handler_default { public function is_select($query) { if (preg_match("@from employees where@ism", $query)) { /* cache query for mysqlnd_qc.ttl seconds */ return true; } return parent::is_select($query); } } $qc = new my_qc(); mysqlnd_qc_change_handler($qc); ?>
  • 38. Resources • php.net/mysqlnd_qc – Installation, Examples, Functions • php.net/mysqlnd – Introduction, Changes, C plugin API • slideshare.net/nixnutz/presentations – QC Basics – QC User defined storage handler – QC Statistics – QC Benchmark impressions
  • 39.
  • 40. The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.