Download - Caching for Cash: Benchmarking and Profiling
![Page 1: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/1.jpg)
CACHING FOR CASH - BENCHMARKING
Scott MacVicar + Helgi Þormar Þorbjörnssonphp|works 2008
![Page 2: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/2.jpg)
GOALS
Learn how to find slow pages
Locate slow blocks of code
Apply minor optimisations
![Page 3: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/3.jpg)
THOUGHT STEPS
Things seem a bit slow
Take a guess whats slow
Browse lots of code
![Page 4: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/4.jpg)
SYSTEM COMPONENTS
Appliation Server
Database Server
Application
Database
Network
![Page 5: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/5.jpg)
PAGE BENCHMARKING
Single Request doesn’t matter
Average time for maximum amount of users
Hopefully at worst it scales linearly
![Page 6: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/6.jpg)
REQUIREMENTS
Same hardware configuration
Same server configuration
Same network interface speed (100mbps)
Basically your “staging server”
![Page 7: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/7.jpg)
STEPS TO BENCHMARK
Record server load
Run our tests at least 3 times
Take average of tests
![Page 8: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/8.jpg)
BENCHMARKING TOOLS
Apache Bench
Apache Flood
Siege
![Page 9: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/9.jpg)
APACHE BENCH
Shows requests per second
Bundled with Apache
Gives relative idea of load
![Page 10: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/10.jpg)
APACHE BENCH - DEMO
1000 Requests with 5 at a timeab -n 1000 -c 5 http://localhost/phpBB3/index.php
1000 requests with 5 at a time using keep aliveab -n 1000 -c 5 -k http://localhost/phpBB3/index.php
Output results to Excel / GNUPlotab -n 1000 -c 5 -g http://localhost/phpBB3/index.php
![Page 11: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/11.jpg)
ISSUES WITH APACHE BENCH
Synthetic Benchmark
No way to emulate users
![Page 12: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/12.jpg)
APACHE FLOOD
Profile driven benchmarking
XML Based config
Use variables on pages
![Page 13: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/13.jpg)
XML FORMAT
URLLIST
FARM
FARMER
PROFILE
![Page 14: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/14.jpg)
URLIST
Simple group of URLs
Supports postdelay and predelay
![Page 15: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/15.jpg)
FARMER
Single User
Can use URLLIST in various ways
Random Order
Round Robin
Keep-Alive
![Page 16: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/16.jpg)
FARM
It’s where the farmers work
Controls the way the farmers work
Creates farmers too
![Page 17: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/17.jpg)
PROFILE
Runtime configuration
Can change various settings
socket
report
![Page 18: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/18.jpg)
USE CASES
User visits main page
User visits main page then download page
User visits main page then download and downloads a file
![Page 19: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/19.jpg)
SINGLE PAGE
Page Image ImageKeep Alive
![Page 20: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/20.jpg)
SINGLE PAGE XML
![Page 21: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/21.jpg)
TWO PAGE VISITS
Page Image ImageKeep Alive
Page Image ImageKeep Alive
30 secslater
![Page 22: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/22.jpg)
TWO PAGE VISITS XML
![Page 23: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/23.jpg)
TWO PAGE VISITS AND DOWNOAD
Page Image ImageKeep Alive
Page Image ImageKeep Alive
30 secslater
ISO
15 secslater
![Page 24: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/24.jpg)
TWO PAGE VISIT AND DOWNOAD XML
![Page 25: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/25.jpg)
SETUP A PROFILE
enable keepalive
use the relative times output format
check for 200 OK
![Page 26: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/26.jpg)
PROFILE XML
![Page 27: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/27.jpg)
JOE THE FARMER
![Page 28: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/28.jpg)
FARM FOR JOE TO WORK ON
![Page 29: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/29.jpg)
RUNNING FLOOD
flood <configuration.xml> > output.file
anaylze-relative output.file
![Page 30: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/30.jpg)
VMWARE INSTALL
Run VMware-player-2.5.0-118166.exe Run VMWare-fusion.dmg
Run VMware-
Player-2.5.0-118166.i386.bundle
Reboot
Copy Fedora 10 Folder to DiskLoad via VMWare php / password
![Page 31: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/31.jpg)
TASK
• Visit http://localhost/phpBB3/• View a forum after 20 seconds• View a thread after 5 seconds• Click reply after 60 seconds• Sample file in flood-examples folder
![Page 32: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/32.jpg)
SIEGE
Provides functionality of Apache Bench and Flood
Supports GET and POST with a simple syntax
Benchmark and Internet mode
![Page 33: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/33.jpg)
SIEGE COMMANDS
1000 Requests with 5 at a timesiege -b -r 1000 -c 5 http://localhost/phpBB3/index.php
10 seconds with concurrency of 5siege -b -c 5 -t 10 http://localhost/phpBB3/index.php
Read urls.txt for a list of URLssiege -b -n 1000 -c 5
![Page 34: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/34.jpg)
SPROXY
Creates local socks proxy on your machine
Set your browser to use the local proxy, port 9001
Browse your site with the actions you wish
urls.txt is written with the POST and GET data
![Page 35: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/35.jpg)
OTHER BENCHMARKING TOOLS
JMeter
httperf
Web Application Stress Tool
OpenWebLoad
![Page 36: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/36.jpg)
PROFILING
![Page 37: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/37.jpg)
WHAT IS PROFILING
Examines the performance characteristics
Records every function call
Tracks execution time
Tracks memory usage
![Page 38: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/38.jpg)
PROFILING TOOLS
XDebug
apd
![Page 39: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/39.jpg)
XDEBUG
Debugger
Code Coverage
Memory and Executon time
![Page 40: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/40.jpg)
XDEBUG PROTECTIONS
Stack overflow in PHP
Infinite Recursion
![Page 41: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/41.jpg)
![Page 42: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/42.jpg)
ERROR MESSAGE HELPING
![Page 43: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/43.jpg)
XDEBUG HELPFUL ERROR MESSAGES
![Page 44: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/44.jpg)
MORE ERROR MESSAGE HELPING
![Page 45: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/45.jpg)
EXECUTION TIME
![Page 46: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/46.jpg)
MEMORY USAGE
![Page 47: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/47.jpg)
EXECUTION TRACE
xdebug.auto_trace=1
xdebug.trace_output_dir=/tmp
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.trace_output_name=trace.%c
![Page 48: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/48.jpg)
EXECUTION TRACE
![Page 49: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/49.jpg)
PARTIAL EXECUTION TRACE
Tracing only parts of an application with xdebug_start_trace() and xdebug_stop_trace().
Fetching the trace file name that is being used with xdebug_get_tracefile_name().
Changing how much data is shown with xdebug.var_display_max_children, xdebug.var_display_max_data and xdebug.var_display_max_depth.
![Page 50: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/50.jpg)
CODE COVERAGE
Finds unexecuted code
xdebug_start_code_coverage()
xdebug_get_code_coverage()
xdebug_stop_code_coverage()
![Page 51: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/51.jpg)
CODE COVERAGE SAMPLE
![Page 52: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/52.jpg)
CODE COVERAGE OUTPUT
![Page 53: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/53.jpg)
PROFILING
Execute action as normal in browser
Outputs cachegrind file
INI settings:xdebug.profiler_enable=1 ; enable profilerxdebug.profile_output_dir=/tmp ; output directoryxdebug.profile_output_name=cachegrind.out.%p
![Page 54: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/54.jpg)
PROFILING CONTINUED
Locate parts of the code that is slow
Work down tree to find the slow sections
Can it be cached? Can it be optimized?
Occasionally built?
![Page 55: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/55.jpg)
VIEWING PROFILE
KCacheGrind
MacCallGrind
WinCacheGrind
Carica CacheGrind
![Page 56: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/56.jpg)
PROFILING DEMO
![Page 57: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/57.jpg)
TASK
sudo nano -w /etc/php.d/xdebug.iniremove ; from xdebug.profiler_enabled=1
Profile a page on Wordpress
Profile a page on phpBB
Try to find something slow you think could be improved
20 minutes
![Page 58: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/58.jpg)
APD
Lives in PECL
Similar to XDebug
Doesn’t require KCachegrind
Still only PHP 4
![Page 59: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/59.jpg)
APD
apd_set_pprof_trace() to enable profiler
pprof is a script to interpret the trace
Outputs to apd.dumpdir
![Page 60: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/60.jpg)
BRINGING IT TOGETHER
Use profiler with benchmarks
Profiling can be run on production sites
Optimise slow code
![Page 61: Caching for Cash: Benchmarking and Profiling](https://reader033.vdocuments.site/reader033/viewer/2022061103/5405fba08d7f72a6768b4ff2/html5/thumbnails/61.jpg)
RESOURCES
Lunch - back at 1pm for Caching
http://talks.macvicar.net/
http://httpd.apache.org/test/flood/
http://xdebug.org/docs/
http://www.joedog.org