award-winning technology: oxid loves the query cache

Download Award-winning technology: Oxid loves the query cache

If you can't read please download the document

Upload: ulf-wendel

Post on 16-Apr-2017

11.837 views

Category:

Technology


0 download

TRANSCRIPT

PowerPoint-Prsentation

Award-winning technology








Fast, faster, fastest limited seats!

Ulf Wendel, MySQL/Sun/Oracle/TellMeWhatIsNext

Environmental friendly technology

Plugins: easy, fast, secure

The speaker says...

Fun is a function of performance. Performance gains, performance wins are one of the primary purposes of a cache. Before we look at the mysqlnd cache plugin, let's see some performance figures.

Maybe, you'll smile about any benchmark you read in the future.

Performance: open 24h

Your ultimate OpenSource Shopsoftware E-Commerce solution for growth and profitability.

http://www.oxid-esales.com/

PHP 5.2.15-dev

4.61 Requests/s

RES 22...23m

./configure' '--with-mysql=/usr/local/mysql/' '--with-gd'
'--with-jpeg-dir=/usr/lib64/' '--with-png-dir=/home/nixnutz/ftp/libpng-1.4.4/install' '--enable-mbstring' '--with-curl' '--enable-bcmath' '--with-apxs2=/usr/local/apache2/bin/apxs'

100%

The speaker says...

We are benchmarking Oxid on a dated two machines setup. One machine runs Apache 2.2.15 + PHP, the other machine runs MySQL 5.1.25-rc.

Our hardware consists of two machines with using dual-core x86_64 CPUs. We run on Linux, have 4GB RAM and use RAID-0. The machines are connected via a 1GBit ethernet. The webserver is CPU saturated. The database server is bored... - no CPU, no I/O wait. Network latency 1MB

The speaker says...

Almost 200% performance win!

Same hardware, same software, same query cache configuration, still a two machine setup, still PHP 5.3.4-dev using APC.

A minor variation on using Apache bench:ab -n80 -c8 http://127.0.0.1/oxid

S.O.S cache entry expires

Client 1MySQL

Client 2...nCache Hit

MySQL

Client 1Client 2...n

The speaker says...

Plan your cache strategy carefully! If not properly planned, caching can be counter productive. For example, test what happens if a very popular cache entry used by many clients expires. For the time it takes to refresh the cache entry all clients formerly using the invalidated cache entry will contact the database. The load of the MySQL server will increase suddenly MySQL will be slammed. Due to the high load it takes longer and longer to refresh the cache entry. MySQL gets overloaded: a spiral to death.

Slam defense: serve stale!

Client 1MySQL

Client 2...nExpired

MySQL

Client 1Client 2...n

Cache Hit

Refresh

The speaker says...

To avoid slamming the MySQL Server the query cache plugin has a special TTL based slam protection operation mode. If a client hits an expired cache entry (cache miss) and slam protection is turned on the client gets a cache miss but the cache entry lifetime will be extended by a configurable time. All other clients also using the expired cache entry will get a cache hit because of the extended lifetime. Only the first client, which got a cache miss, contacts the MySQL Server to refresh the expired cache entry. Ideally, it will refresh the expired cache entry before the extended lifetime ends and MySQL does not get slammed because of a sudden massive load.

The 150+ statistics of mysqlnd

Collected by: mysqlnd

php.net/manual/en/mysqlnd.stats.php Scope: process, connection

Process: mysqli_get_client_stats()

Connection: mysqli_get_connection_stats()

Contents: wide range

Network related

Result set related

Connection related

20 statistics of the cache core

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

Commercials

To new shores with MAYFLOWER

Mayflower is Germany's largest service provider in terms of PHP programming.No matter whether you need corporation-wide Intranets, communities, e-business and e-commerce systems or customised solutions - we are the right partner to cooperate with. Find out more about our services in the field of software development.

http://www.mayflower.de/en/contact

5 slots + 1 commercial

Hacking Oxid

A basic user defined storage handler

The speaker says...

Read and enjoy the slides. It aint complicated!

php.ini

[PHP]mysqlnd_qc.collect_normalized_query_trace=1mysqlnd_qc.collect_query_trace=1mysqlnd_qc.query_trace_bt_depth=20mysqlnd_qc.collect_statistics=1auto_prepend_file=/home/nixnutz/www/htdocs/oxid/prepend.phpauto_append_file=/home/nixnutz/www/htdocs/oxid/append.php

auto_prepend_file

auto_append_file

$queries = mysqlnd_qc_get_query_trace_log();$distinct = array();$max_store_time = $max_store_time_idx = 0;

foreach ($queries as $k => $details) { if (!isset($distinct[$details['query']])) $distinct[$details['query']] = 0; else $distinct[$details['query']]++; if ($details['store_time'] > $max_store_time) { $max_store_time = $details['store_time']; $max_store_time_idx = $k; }}printf("Total: %d, distinct %d\n", count($queries), count($distinct));var_dump($queries[$max_store_time_idx]);

Query monitor findings...

Total: 329, distinct 296array(8) { ["query"]=> string(348) "select [... snip ...]" ["origin"]=> String(1210) "#0 [... snip ...] mysql_driver.inc(352): mysql_query('select oxmanufa...', Resource id #11)[...]#11 {main}" ["run_time"] => int(0) ["store_time"] => int(558) ["eligible_for_caching"] => bool(false) ["no_table"] => bool(false) ["was_added"] => bool(false) ["was_already_in_cache"] => bool(false)}

User defined storage handler

Procedural

php.net/manual/en/function.mysqlnd_qc_set_user_handlers.phpCallback functions

Object oriented

slideshare.net/nixnutz/mysqlnd-query-cache-plugin-userdefined-storage-handlerInterface mysqlnd_qc_handler

Andrey hates me

Extending mysqlnd_qc_handler_default

Most basic user storage handler

Google on diet

Does it work?

Marketing kills you!

array(26) { ["cache_hit"] => string(1) "0" ["cache_miss"] => string(3) "179" ["cache_put"] => string(2) "90" [... snip ...]}(3591/117) select oxfixed, oxseourl, oxexpired, oxt ...(3206/132) select oxfixed, oxseourl, oxexpired, oxt

Scope: process

array(26) { ["cache_hit"] => string(3) "270" ["cache_miss"] => string(3) "446" ["cache_put"] => string(2) "90" [.. snip ...]}(30/14) select oxfixed, oxseourl, oxexpired, oxt ...(30/27) select oxfixed, oxseourl, oxexpired, oxt ...

Commercials

Qafoo

Increase your Return On Investment

Ease your project management

Raise developer motivation

[email protected]

4 slots + 1 commercial

See also...

Documentation and 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

More public plugins on PECL...

mysqlnd_mc

Multi-connect: splits SELECT to be run by different servers and merges the results on the client

mysqlnd_sip

SQL Injection protection: rejects unknown queries to prevent SQL injection attacks

mysqlnd_pscache

Prepared Statement handle cache

THE END

Credits: Andrey Hristov, David Sorria Para Contact: [email protected]

X factorPerformance Win %0,2151050100

Cache (APC)20.357634112792327.9521674140508107.258064516129160.905349794239193.333333333333119.354838709677

Cache (Default)20.220082530949128.251121076233291.1290322580645120.16460905349893.333333333333312.9032258064516