cvs: presentations / optimizing-mysql-and-php.xml /slides/optimizing-mysql-and-php apache.xml apd.xml benchmarking-code.xml benchmarking-pages.xml
bottlenecks.xml bottlenecks2.xml cache-lite.xml cpu.xml disk.xml engine-patches.xml execution-path-with-cache.xml execution-path.xml explain.xml
funky-caching.xml gzip-compression.xml heap.xml innodb.xml memory.xml myisam.xml mysql-buffers.xml mysql-interface.xml mysql-optimizer.xml mysql.xml
network.xml opcode-caches.xml other-talks-phpcon-2003.xml replication.xml

From: Date: Mon, 03 Nov 2003 16:28:02 +0000
Subject: cvs: presentations / optimizing-mysql-and-php.xml /slides/optimizing-mysql-and-php apache.xml apd.xml benchmarking-code.xml benchmarking-pages.xml
bottlenecks.xml bottlenecks2.xml cache-lite.xml cpu.xml disk.xml engine-patches.xml execution-path-with-cache.xml execution-path.xml explain.xml
funky-caching.xml gzip-compression.xml heap.xml innodb.xml memory.xml myisam.xml mysql-buffers.xml mysql-interface.xml mysql-optimizer.xml mysql.xml
network.xml opcode-caches.xml other-talks-phpcon-2003.xml replication.xml
Groups: php.pres 
Request: Send a blank email to pres+get-888@lists.php.net to get a copy of this message
jimw Mon Nov 3 11:28:02 2003 EDT Added files: /presentations/slides/optimizing-mysql-and-php apache.xml apd.xml benchmarking-code.xml benchmarking-pages.xml bottlenecks.xml bottlenecks2.xml cache-lite.xml cpu.xml disk.xml engine-patches.xml execution-path-with-cache.xml execution-path.xml explain.xml funky-caching.xml gzip-compression.xml heap.xml innodb.xml memory.xml myisam.xml mysql-buffers.xml mysql-interface.xml mysql-optimizer.xml mysql.xml network.xml opcode-caches.xml other-talks-phpcon-2003.xml replication.xml Modified files: /presentations optimizing-mysql-and-php.xml Log: initial version of optimizing mysql and php slides -- still one slide to do

Index: presentations/optimizing-mysql-and-php.xml diff -u presentations/optimizing-mysql-and-php.xml:1.1 presentations/optimizing-mysql-and-php.xml:1.2 --- presentations/optimizing-mysql-and-php.xml:1.1 Fri Oct 31 20:36:01 2003 +++ presentations/optimizing-mysql-and-php.xml Mon Nov 3 11:28:01 2003 @@ -12,7 +12,50 @@ <slide>slides/intro/titlepage.xml</slide> -<!-- stuff goes here --> +<slide>slides/optimizing-mysql-and-php/bottlenecks.xml</slide> +<slide>slides/optimizing-mysql-and-php/cpu.xml</slide> +<slide>slides/optimizing-mysql-and-php/memory.xml</slide> +<slide>slides/optimizing-mysql-and-php/disk.xml</slide> +<slide>slides/optimizing-mysql-and-php/network.xml</slide> + +<slide>slides/optimizing-mysql-and-php/bottlenecks2.xml</slide> + +<slide>slides/optimizing-mysql-and-php/apache.xml</slide> + +<slide>slides/optimizing-mysql-and-php/benchmarking-pages.xml</slide> + +<slide>slides/optimizing-mysql-and-php/execution-path.xml</slide> +<slide>slides/optimizing-mysql-and-php/execution-path-with-cache.xml</slide> +<slide>slides/optimizing-mysql-and-php/opcode-caches.xml</slide> + +<slide>slides/optimizing-mysql-and-php/engine-patches.xml</slide> + +<slide>slides/optimizing-mysql-and-php/cache-lite.xml</slide> +<slide>slides/optimizing-mysql-and-php/funky-caching.xml</slide> + +<slide>slides/optimizing-mysql-and-php/gzip-compression.xml</slide> + +<slide>slides/optimizing-mysql-and-php/apd.xml</slide> + +<slide>slides/optimizing-mysql-and-php/benchmarking-code.xml</slide> + +<slide>slides/optimizing-mysql-and-php/mysql-interface.xml</slide> + +<slide>slides/optimizing-mysql-and-php/mysql.xml</slide> + +<slide>slides/optimizing-mysql-and-php/myisam.xml</slide> +<slide>slides/optimizing-mysql-and-php/innodb.xml</slide> +<slide>slides/optimizing-mysql-and-php/heap.xml</slide> + +<slide>slides/optimizing-mysql-and-php/mysql-optimizer.xml</slide> + +<slide>slides/optimizing-mysql-and-php/explain.xml</slide> + +<slide>slides/optimizing-mysql-and-php/mysql-buffers.xml</slide> + +<slide>slides/optimizing-mysql-and-php/replication.xml</slide> + +<slide>slides/optimizing-mysql-and-php/other-talks-phpcon-2003.xml</slide> <slide>slides/community/fin.xml</slide> Index: presentations/slides/optimizing-mysql-and-php/apache.xml +++ presentations/slides/optimizing-mysql-and-php/apache.xml <slide title="Apache"> <list title="Configuring Apache for Performance"> <bullet>StartServers, MinSpareServers, MaxSpareServers, MaxClients</bullet> <bullet>KeepAlive, KeepAliveTimeout</bullet> <bullet>Timeout</bullet> <bullet>SendBufferSize</bullet> <bullet>MaxRequestsPerChild</bullet> <bullet>HostnameLookups</bullet> </list> </slide> Index: presentations/slides/optimizing-mysql-and-php/apd.xml +++ presentations/slides/optimizing-mysql-and-php/apd.xml <slide title="Profiling with APD"> <example type="shell">$ pear install apd</example> <example>zend_extension = /path/to/directory/apd.so apd.dumpdir = /tmp</example> <example type="php"><![CDATA[<?php apd_set_pprof_trace(); /* rest of script */ ?>]]> </example> <example type="shell"><![CDATA[$ pprof -z /tmp/pprof.1234 Trace for /home/jimw/pres2/show.php Total Elapsed Time = 0.31 Total System Time = 0.00 Total User Time = 0.24 Real User System secs/ cumm %Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name -------------------------------------------------------------------------------------- 54.2 0.13 0.15 0.13 0.15 0.00 0.00 9 0.0144 0.0167 1052240 require_once 12.5 0.03 0.03 0.03 0.03 0.00 0.00 126 0.0002 0.0002 7800 strtolower 8.3 0.02 0.02 0.02 0.02 0.00 0.00 10 0.0020 0.0020 213832 define 4.2 0.01 0.01 0.01 0.01 0.00 0.00 2 0.0050 0.0050 7328 htmlspecialchars 4.2 0.01 0.01 0.01 0.01 0.00 0.00 4 0.0025 0.0025 -4032 feof 4.2 0.01 0.01 0.01 0.01 0.00 0.00 4 0.0025 0.0025 3248 _example->_example 4.2 0.01 0.01 0.01 0.01 0.00 0.00 57 0.0002 0.0002 2896 count 4.2 0.01 0.01 0.01 0.01 0.00 0.00 37 0.0003 0.0003 6336 xml_presentation->_add_attribs 4.2 0.01 0.01 0.01 0.01 0.00 0.00 2 0.0050 0.0050 -20704 fclose 0.0 0.00 0.01 0.00 0.01 0.00 0.00 5 0.0000 0.0020 64 xml_slide->starthandler 0.0 0.00 0.02 0.00 0.02 0.00 0.00 2 0.0000 0.0100 -208 xml_slide->parsestring 0.0 0.00 0.00 0.00 0.00 0.00 0.00 1 0.0000 0.0000 528 _slide->_slide 0.0 0.00 0.00 0.00 0.00 0.00 0.00 1 0.0000 0.0000 2816 html->display 0.0 0.00 0.00 0.00 0.00 0.00 0.00 5 0.0000 0.0000 288 xml_slide->_add_attribs 0.0 0.00 0.00 0.00 0.00 0.00 0.00 5 0.0000 0.0000 88 xml_slide->endhandler 0.0 0.00 0.01 0.00 0.01 0.00 0.00 75 0.0000 0.0001 4048 xml_slide->cdatahandler 0.0 0.00 0.03 0.00 0.03 0.00 0.00 1 0.0000 0.0300 -16 xml_slide->parse 0.0 0.00 0.00 0.00 0.00 0.00 0.00 1 0.0000 0.0000 72 xml_slide->seterrorhandling 0.0 0.00 0.00 0.00 0.00 0.00 0.00 1 0.0000 0.0000 208 dirname 0.0 0.00 0.00 0.00 0.00 0.00 0.00 1 0.0000 0.0000 -120 xml_slide->pear ]]></example> </slide> Index: presentations/slides/optimizing-mysql-and-php/benchmarking-code.xml +++ presentations/slides/optimizing-mysql-and-php/benchmarking-code.xml <slide title="Benchmarking Code"> <example type="php" result="1"><![CDATA[<?php require_once 'Benchmark/Iterate.php'; $benchmark = new Benchmark_Iterate; function fact($n) { if ($n <= 1) return 1; return $n * fact($n - 1); } $benchmark->run(20, 'fact', '1000'); $result = $benchmark->get(); print $result['mean']; ?>]]></example> </slide> Index: presentations/slides/optimizing-mysql-and-php/benchmarking-pages.xml +++ presentations/slides/optimizing-mysql-and-php/benchmarking-pages.xml <slide title="Benchmarking Pages"> <blurb> The %ab% (Apache benchmark) utility can be used for basic page-level benchmarking: </blurb> <example type="shell"> $ ab -c 2 -n 50 http://localhost/test.php?n=500 </example> <example type="shell"> This is ApacheBench, Version 1.3d &lt;$Revision: 1.1 $&gt; apache-1.3 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient).....done Server Software: Apache/1.3.28 Server Hostname: localhost Server Port: 80 Document Path: /test.php?n=500 Document Length: 6 bytes Concurrency Level: 2 Time taken for tests: 0.979 seconds Complete requests: 50 Failed requests: 0 Broken pipe errors: 0 Total transferred: 10353 bytes HTML transferred: 306 bytes Requests per second: 51.07 [#/sec] (mean) Time per request: 39.16 [ms] (mean) Time per request: 19.58 [ms] (mean, across all concurrent requests) Transfer rate: 10.58 [Kbytes/sec] received Connnection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.0 0 0 Processing: 18 38 55.4 21 361 Waiting: 18 38 55.4 21 361 Total: 18 38 55.4 21 361 Percentage of the requests served within a certain time (ms) 50% 21 66% 37 75% 39 80% 39 90% 49 95% 83 98% 222 99% 361 100% 361 (last request) </example> </slide> Index: presentations/slides/optimizing-mysql-and-php/bottlenecks.xml +++ presentations/slides/optimizing-mysql-and-php/bottlenecks.xml <slide title="Bottlenecks"> <list title="Hardware Bottlenecks"> <bullet>CPU</bullet> <bullet>Memory</bullet> <bullet>Disk</bullet> <bullet>Network</bullet> </list> </slide> Index: presentations/slides/optimizing-mysql-and-php/bottlenecks2.xml +++ presentations/slides/optimizing-mysql-and-php/bottlenecks2.xml <slide title="Bottlenecks"> <list title="Software Bottlenecks"> <bullet>Apache</bullet> <bullet>PHP</bullet> <bullet>Application code</bullet> <bullet>Database</bullet> </list> </slide> Index: presentations/slides/optimizing-mysql-and-php/cache-lite.xml +++ presentations/slides/optimizing-mysql-and-php/cache-lite.xml <slide title="Cache/Lite"> <example type="php"><![CDATA[<?php /* Include the class */ require_once('Cache/Lite.php'); /* Set a key for this cache item */ $id = 'newsitem1'; /* Set a few options */ $options = array( 'cacheDir' => '/var/cache/news/', 'lifeTime' => 3600 ); /* Create a Cache_Lite object */ $Cache_Lite = new Cache_Lite($options); /* Test if there is a valid cache-entry for this key */ if ($data = $Cache_Lite->get($id)) { /* Cache hit! */ } else { /* Cache miss! */ ob_start(); /* Generate content */ $data = ob_get_contents(); $Cache_Lite->save($data); } ?>]]></example> </slide> Index: presentations/slides/optimizing-mysql-and-php/cpu.xml +++ presentations/slides/optimizing-mysql-and-php/cpu.xml <slide title="CPU"> <list title="Characteristics"> <bullet>Number</bullet> <bullet>Speed</bullet> <bullet>Cache</bullet> <bullet>Bandwidth (bus speed)</bullet> </list> <blurb> The most basic optimization: do less work. </blurb> </slide> Index: presentations/slides/optimizing-mysql-and-php/disk.xml +++ presentations/slides/optimizing-mysql-and-php/disk.xml <slide title="Disk"> <list title="Characteristics"> <bullet>Seek speed</bullet> <bullet>Read speed</bullet> <bullet>Write speed</bullet> <bullet>Redundancy</bullet> </list> <blurb> Basic optimization: read and write less! </blurb> </slide> Index: presentations/slides/optimizing-mysql-and-php/engine-patches.xml +++ presentations/slides/optimizing-mysql-and-php/engine-patches.xml <slide title="Engine Patches"> <blurb>Sterling and Thies have produced a patch with some clever engine optimizations.</blurb> <list> <bullet>http://www.edwardbear.org/optimizations</bullet> <bullet>http://www.edwardbear.org/fasterharderstronger.diff</bullet> </list> <blurb fontsize="5em" align="middle"> Use at your own risk! </blurb> </slide> Index: presentations/slides/optimizing-mysql-and-php/execution-path-with-cache.xml +++ presentations/slides/optimizing-mysql-and-php/execution-path-with-cache.xml <slide> <title>Execution Path with Cache</title> <!-- steal another slide from rasmus --> <image align="middle" title="Execution with a cache" filename="../intro/php_opcode_caches.png" /> </slide> Index: presentations/slides/optimizing-mysql-and-php/execution-path.xml +++ presentations/slides/optimizing-mysql-and-php/execution-path.xml <slide title="Execution Path"> <!-- borrow graphic from rasmus --> <image align="middle" title="Standard PHP Execution Path" filename="../intro/php_flow.png" /> </slide> Index: presentations/slides/optimizing-mysql-and-php/explain.xml +++ presentations/slides/optimizing-mysql-and-php/explain.xml <slide title="EXPLAIN"> <!-- TODO --> </slide> Index: presentations/slides/optimizing-mysql-and-php/funky-caching.xml +++ presentations/slides/optimizing-mysql-and-php/funky-caching.xml <slide title="Funky caching"> <blurb title="The Goal"> Don't do the cache-checking with PHP code. </blurb> <example title="The Solution">ErrorDocument 404 /generate-page.php</example> <example title="The Script"><![CDATA[<?php if (preg_match('^/article-(\d+).html$!', $_SERVER['REDIRECT_URI'], $m)) { ob_start(); /* Do stuff to generate page */ $data = ob_get_contents(); ob_end_clean(); echo $data; $fn = "article-$m[0].html.".getmypid(); $fd = fopen($fn, "w") or exit; fputs($fd, $data); fclose($fd); rename($fn, "article-$m[0].html"); } else { header("HTTP/1.0 404 Not found"); /* Generate 404 message here */ } ?>]]> </example> </slide> Index: presentations/slides/optimizing-mysql-and-php/gzip-compression.xml +++ presentations/slides/optimizing-mysql-and-php/gzip-compression.xml <slide title="Gzip Compression"> <list> <bullet>Pro: send less data over the network</bullet> <bullet>Con: requires more CPU processing</bullet> </list> <example title="ob_gzhandler"><![CDATA[<?php ob_start('ob_gzhandler');?>]]></example> <example title="zlib.output_compression">zlib.output_compression = On zlib.compression_level = 3 </example> <example title="mod_gzip">LoadModule gzip_module lib/apache/mod_gzip.so </example> </slide> Index: presentations/slides/optimizing-mysql-and-php/heap.xml +++ presentations/slides/optimizing-mysql-and-php/heap.xml <slide title="HEAP"> <list title="HEAP"> <bullet>Not transaction-capable</bullet> <bullet>Stored in memory (so data lost on shutdown)</bullet> <bullet>Hash indexes (great for indexed lookups, not for range queries)</bullet> <bullet>Btree indexes in 4.1</bullet> </list> <list title="Dynamic"> <bullet>Not transaction-capable</bullet> <bullet>Migrates between memory and disk</bullet> <bullet>New in 4.1</bullet> </list> <list title="Cluster"> <bullet>5.0?</bullet> </list> </slide> Index: presentations/slides/optimizing-mysql-and-php/innodb.xml +++ presentations/slides/optimizing-mysql-and-php/innodb.xml <slide title="InnoDB"> <list> <bullet>Transaction-capable</bullet> <bullet>Row-level locking</bullet> <bullet>MVCC architecture</bullet> <bullet>Standard part of 4.0 (available in 3.23)</bullet> <bullet>Great for balanced read/write usage</bullet> </list> <example type="sql"> CREATE TABLE order ( ... ) TYPE = InnoDB; ALTER TABLE address TYPE = InnoDB; </example> <list title="BDB"> <bullet>Transaction-capable</bullet> <bullet>Page-level locking</bullet> <bullet>Built on top of Sleepycat Software's Berkeley DB</bullet> <bullet>Part of MySQL Max</bullet> </list> </slide> Index: presentations/slides/optimizing-mysql-and-php/memory.xml +++ presentations/slides/optimizing-mysql-and-php/memory.xml <slide title="Memory"> <list title="Characteristics"> <bullet>Amount</bullet> <bullet>Speed</bullet> </list> <blurb> The most basic optimization: use less memory. </blurb> </slide> Index: presentations/slides/optimizing-mysql-and-php/myisam.xml +++ presentations/slides/optimizing-mysql-and-php/myisam.xml <slide title="MyISAM"> <list> <bullet>Not transaction-capable</bullet> <bullet>Table-level locking</bullet> <bullet>Fast appends (great for logging)</bullet> <bullet>Can be compressed</bullet> </list> <blurb>The MERGE table type allows you to treat several MyISAM tables as a single table: great for chunking logs into manageable pieces (so parts can be compressed).</blurb> </slide> Index: presentations/slides/optimizing-mysql-and-php/mysql-buffers.xml +++ presentations/slides/optimizing-mysql-and-php/mysql-buffers.xml <slide title="Buffer tuning"> <example>http://jeremy.zawodny.com/mysql/mytop/</example> <list title="Buffers to tune"> <bullet>Key buffer (MyISAM): %key_buffer_size%</bullet> <bullet>Table cache (all): %table_cache%</bullet> <bullet>Record buffer (per session): %read_buffer_size%, %read_rnd_buffer_size%</bullet> <bullet>Sort buffer (per session): %sort_buffer_size%</bullet> <bullet>Thread cache: %thread_cache_size%</bullet> <bullet>Query cache (4.0+): %query_cache_size%, %query_cache_limit%</bullet> </list> </slide> Index: presentations/slides/optimizing-mysql-and-php/mysql-interface.xml +++ presentations/slides/optimizing-mysql-and-php/mysql-interface.xml <slide title="MySQL Interface"> <blurb fontsize="5em"> The most basic optimization: only ask for data you really need! </blurb> <example type="sql" title="TMI" fontsize="1.5em">SELECT * FROM Country WHERE Name LIKE 'A%' ORDER BY Population DESC</example> <example type="sql" title="Just the Facts" fontsize="1.5em">SELECT Name, Population FROM Country WHERE Name LIKE 'A%' ORDER BY Population DESC LIMIT 5</example> <list title="Other useful functions"> <bullet>%mysql_unbuffered_query()%</bullet> <bullet>%mysql_pconnect()%</bullet> <bullet>%mysqli% interface in PHP5 (prepared statements)</bullet> </list> </slide> Index: presentations/slides/optimizing-mysql-and-php/mysql-optimizer.xml +++ presentations/slides/optimizing-mysql-and-php/mysql-optimizer.xml <slide title="The Query Optimizer"> <list title="How MySQL thinks:"> <bullet>Eliminate rows</bullet> <bullet>Use indexes</bullet> <bullet>Avoid table scans</bullet> <bullet>Consider different join orders</bullet> <bullet>Avoid hitting the disk</bullet> <bullet>Avoid using the data if the index knows enough</bullet> </list> </slide> Index: presentations/slides/optimizing-mysql-and-php/mysql.xml +++ presentations/slides/optimizing-mysql-and-php/mysql.xml <slide title="Optimizing MySQL"> <list> <bullet>Pick the right storage engine</bullet> <bullet>Help the optimizer</bullet> <bullet>Use EXPLAIN</bullet> <bullet>Tune the buffers</bullet> <bullet>Consider replication</bullet> </list> </slide> Index: presentations/slides/optimizing-mysql-and-php/network.xml +++ presentations/slides/optimizing-mysql-and-php/network.xml <slide title="Network"> <list title="Characteristics"> <bullet>Bandwidth</bullet> <bullet>Latency</bullet> <bullet>Concurrency</bullet> </list> <blurb> Basic optimization: send less data! </blurb> </slide> Index: presentations/slides/optimizing-mysql-and-php/opcode-caches.xml +++ presentations/slides/optimizing-mysql-and-php/opcode-caches.xml <slide title="Cache Alternatives"> <list> <bullet>APC (Alternative PHP Cache): in PEAR</bullet> <bullet>Turck MMCache: on SourceForge</bullet> <bullet>IonCube Accelerator - free, but closed source</bullet> <bullet>BWare Afterburner - free, but closed source</bullet> <bullet>Zend Performance Suite - commercial (includes optimizer)</bullet> </list> <blurb title="Installation"> Installation generally only involves loading an extension: </blurb> <example type="shell"> zend_extension = "/usr/local/lib/php/apc.so" </example> </slide> Index: presentations/slides/optimizing-mysql-and-php/other-talks-phpcon-2003.xml +++ presentations/slides/optimizing-mysql-and-php/other-talks-phpcon-2003.xml <slide title="Other talks"> <list> <bullet>Georg Richter, "Loadbalancing und Replication mit PHP5 und MySQL 4.1" (today, right after this session)</bullet> <bullet>Jan Kneschke, "Webserver Performance Tuning" (today at 15:45)</bullet> <bullet>George Schlossnagle: "High Performance PHP" (tomorrow at 14:00)</bullet> <bullet>Derick Rethans, "PHP Internals" (tomorrow at 15:45)</bullet> </list> </slide> Index: presentations/slides/optimizing-mysql-and-php/replication.xml +++ presentations/slides/optimizing-mysql-and-php/replication.xml <slide title="Replication"> <blurb> Replication can be used to distribute the load across multiple machines, particularly in a SELECT-heavy environment: this also reduces (or eliminates) lock contention on the master server when writing data. </blurb> <!-- borrow graphic from george --> <image filename="../hpp/replication.png" align="center"/> <example type="shell" title="Master Server Configuration">[mysqld] log-bin server-id=1</example> <example type="shell" title="Slave User"><![CDATA[GRANT REPLICATION SLAVE ON *.* TO repl@"%" IDENTIFIED BY 'foobar';]]></example> <example type="shell" title="Slave Server Configuration">[mysqld] set-variable = max_connections=200 log-bin master-host=192.168.0.1 master-user=repl master-password=foobar master-port=3306 server-id=2</example> </slide>
« previous php.pres (#888) next »