CACHING FOR CASH -
   BENCHMARKING
Scott MacVicar + Helgi Þormar Þorbjörnsson
             php|works 2008
GOALS



Learn how to find slow pages

Locate slow blocks of code

Apply minor optimisations
THOUGHT STEPS



Things seem a bit slow

Take a guess whats slow

Browse lots of code
SYSTEM COMPONENTS


Appliation Server

Database Server

Application

Database

Network
PAGE BENCHMARKING



Single Request doesn’t matter

Average time for maximum amount of users

Hopefully at worst it scales...
REQUIREMENTS


Same hardware configuration

Same server configuration

Same network interface speed (100mbps)

Basically you...
STEPS TO BENCHMARK



Record server load

Run our tests at least 3 times

Take average of tests
BENCHMARKING TOOLS



Apache Bench

Apache Flood

Siege
APACHE BENCH


Shows requests per
second

Bundled with Apache

Gives relative idea of
load
APACHE BENCH - DEMO

1000 Requests with 5 at a time
ab -n 1000 -c 5 http://localhost/phpBB3/index.php

1000 requests with ...
ISSUES WITH APACHE BENCH



Synthetic Benchmark

No way to emulate users
APACHE FLOOD



Profile driven
benchmarking

XML Based config

Use variables on pages
XML FORMAT


URLLIST

FARM

FARMER

PROFILE
URLIST



Simple group of URLs

Supports postdelay and predelay
FARMER


Single User

Can use URLLIST in various ways

  Random Order

  Round Robin

  Keep-Alive
FARM



It’s where the farmers work

Controls the way the farmers work

Creates farmers too
PROFILE


Runtime configuration

Can change various settings

  socket

  report
USE CASES



User visits main page

User visits main page then download page

User visits main page then download and down...
SINGLE PAGE


                Keep Alive
 Page   Image                Image
SINGLE PAGE XML
TWO PAGE VISITS


                       Keep Alive
   Page        Image                Image

     30 secs
      later

 ...
TWO PAGE VISITS XML
TWO PAGE VISITS AND
   DOWNOAD
                         Keep Alive
     Page        Image                Image

       30 ...
TWO PAGE VISIT AND
 DOWNOAD XML
SETUP A PROFILE



enable keepalive

use the relative times output format

check for 200 OK
PROFILE XML
JOE THE FARMER
FARM FOR JOE TO WORK ON
RUNNING FLOOD



flood <configuration.xml> > output.file

anaylze-relative output.file
VMWARE INSTALL


                                                         Run
     Run VMware-                            ...
TASK
• Visit http://localhost/phpBB3/
• View a forum after 20 seconds
• View a thread after 5 seconds
• Click reply after ...
SIEGE



Provides functionality of Apache Bench and Flood

Supports GET and POST with a simple syntax

Benchmark and Inter...
SIEGE COMMANDS

1000 Requests with 5 at a time
siege -b -r 1000 -c 5 http://localhost/phpBB3/index.php

10 seconds with co...
SPROXY


Creates local socks proxy on your machine

Set your browser to use the local proxy, port 9001

Browse your site w...
OTHER BENCHMARKING
         TOOLS


JMeter

httperf

Web Application Stress Tool

OpenWebLoad
PROFILING
WHAT IS PROFILING


Examines the performance characteristics

Records every function call

Tracks execution time

Tracks m...
PROFILING TOOLS



XDebug

apd
XDEBUG



Debugger

Code Coverage

Memory and Executon time
XDEBUG PROTECTIONS



Stack overflow in PHP

Infinite Recursion
ERROR MESSAGE HELPING
XDEBUG HELPFUL ERROR
     MESSAGES
MORE ERROR MESSAGE
     HELPING
EXECUTION TIME
MEMORY USAGE
EXECUTION TRACE


xdebug.auto_trace=1

xdebug.trace_output_dir=/tmp

xdebug.collect_params=1

xdebug.collect_return=1

xde...
EXECUTION TRACE
PARTIAL EXECUTION TRACE

Tracing only parts of an application with
xdebug_start_trace() and xdebug_stop_trace().

Fetching...
CODE COVERAGE


Finds unexecuted code

xdebug_start_code_coverage()

xdebug_get_code_coverage()

xdebug_stop_code_coverage...
CODE COVERAGE SAMPLE
CODE COVERAGE OUTPUT
PROFILING


Execute action as normal in browser

Outputs cachegrind file

INI settings:
xdebug.profiler_enable=1 ; enable pr...
PROFILING CONTINUED


Locate parts of the code that is slow

Work down tree to find the slow sections

Can it be cached? Ca...
VIEWING PROFILE


KCacheGrind

MacCallGrind

WinCacheGrind

Carica CacheGrind
PROFILING DEMO
TASK

sudo nano -w /etc/php.d/xdebug.ini
remove ; from xdebug.profiler_enabled=1

Profile a page on Wordpress

Profile a page...
APD


Lives in PECL

Similar to XDebug

Doesn’t require KCachegrind

Still only PHP 4
APD



apd_set_pprof_trace() to enable profiler

pprof is a script to interpret the trace

Outputs to apd.dumpdir
BRINGING IT TOGETHER



Use profiler with benchmarks

Profiling can be run on production sites

Optimise slow code
RESOURCES


Lunch - back at 1pm for Caching

http://talks.macvicar.net/

http://httpd.apache.org/test/flood/

http://xdebug...
Caching for Cash: Benchmarking and Profiling
Upcoming SlideShare
Loading in...5
×

Caching for Cash: Benchmarking and Profiling

2,533

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,533
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
46
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Caching for Cash: Benchmarking and Profiling

  1. 1. CACHING FOR CASH - BENCHMARKING Scott MacVicar + Helgi Þormar Þorbjörnsson php|works 2008
  2. 2. GOALS Learn how to find slow pages Locate slow blocks of code Apply minor optimisations
  3. 3. THOUGHT STEPS Things seem a bit slow Take a guess whats slow Browse lots of code
  4. 4. SYSTEM COMPONENTS Appliation Server Database Server Application Database Network
  5. 5. PAGE BENCHMARKING Single Request doesn’t matter Average time for maximum amount of users Hopefully at worst it scales linearly
  6. 6. REQUIREMENTS Same hardware configuration Same server configuration Same network interface speed (100mbps) Basically your “staging server”
  7. 7. STEPS TO BENCHMARK Record server load Run our tests at least 3 times Take average of tests
  8. 8. BENCHMARKING TOOLS Apache Bench Apache Flood Siege
  9. 9. APACHE BENCH Shows requests per second Bundled with Apache Gives relative idea of load
  10. 10. APACHE BENCH - DEMO 1000 Requests with 5 at a time ab -n 1000 -c 5 http://localhost/phpBB3/index.php 1000 requests with 5 at a time using keep alive ab -n 1000 -c 5 -k http://localhost/phpBB3/index.php Output results to Excel / GNUPlot ab -n 1000 -c 5 -g http://localhost/phpBB3/index.php
  11. 11. ISSUES WITH APACHE BENCH Synthetic Benchmark No way to emulate users
  12. 12. APACHE FLOOD Profile driven benchmarking XML Based config Use variables on pages
  13. 13. XML FORMAT URLLIST FARM FARMER PROFILE
  14. 14. URLIST Simple group of URLs Supports postdelay and predelay
  15. 15. FARMER Single User Can use URLLIST in various ways Random Order Round Robin Keep-Alive
  16. 16. FARM It’s where the farmers work Controls the way the farmers work Creates farmers too
  17. 17. PROFILE Runtime configuration Can change various settings socket report
  18. 18. USE CASES User visits main page User visits main page then download page User visits main page then download and downloads a file
  19. 19. SINGLE PAGE Keep Alive Page Image Image
  20. 20. SINGLE PAGE XML
  21. 21. TWO PAGE VISITS Keep Alive Page Image Image 30 secs later Keep Alive Page Image Image
  22. 22. TWO PAGE VISITS XML
  23. 23. TWO PAGE VISITS AND DOWNOAD Keep Alive Page Image Image 30 secs later Keep Alive Page Image Image 15 secs later ISO
  24. 24. TWO PAGE VISIT AND DOWNOAD XML
  25. 25. SETUP A PROFILE enable keepalive use the relative times output format check for 200 OK
  26. 26. PROFILE XML
  27. 27. JOE THE FARMER
  28. 28. FARM FOR JOE TO WORK ON
  29. 29. RUNNING FLOOD flood <configuration.xml> > output.file anaylze-relative output.file
  30. 30. VMWARE INSTALL Run Run VMware- VMware- Run VMWare-fusion.dmg player-2.5.0-118166.exe Player-2.5.0-118166.i386 .bundle Reboot Copy Fedora 10 Folder to Disk Load via VMWare php / password
  31. 31. 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
  32. 32. SIEGE Provides functionality of Apache Bench and Flood Supports GET and POST with a simple syntax Benchmark and Internet mode
  33. 33. SIEGE COMMANDS 1000 Requests with 5 at a time siege -b -r 1000 -c 5 http://localhost/phpBB3/index.php 10 seconds with concurrency of 5 siege -b -c 5 -t 10 http://localhost/phpBB3/index.php Read urls.txt for a list of URLs siege -b -n 1000 -c 5
  34. 34. 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
  35. 35. OTHER BENCHMARKING TOOLS JMeter httperf Web Application Stress Tool OpenWebLoad
  36. 36. PROFILING
  37. 37. WHAT IS PROFILING Examines the performance characteristics Records every function call Tracks execution time Tracks memory usage
  38. 38. PROFILING TOOLS XDebug apd
  39. 39. XDEBUG Debugger Code Coverage Memory and Executon time
  40. 40. XDEBUG PROTECTIONS Stack overflow in PHP Infinite Recursion
  41. 41. ERROR MESSAGE HELPING
  42. 42. XDEBUG HELPFUL ERROR MESSAGES
  43. 43. MORE ERROR MESSAGE HELPING
  44. 44. EXECUTION TIME
  45. 45. MEMORY USAGE
  46. 46. 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
  47. 47. EXECUTION TRACE
  48. 48. 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.
  49. 49. CODE COVERAGE Finds unexecuted code xdebug_start_code_coverage() xdebug_get_code_coverage() xdebug_stop_code_coverage()
  50. 50. CODE COVERAGE SAMPLE
  51. 51. CODE COVERAGE OUTPUT
  52. 52. PROFILING Execute action as normal in browser Outputs cachegrind file INI settings: xdebug.profiler_enable=1 ; enable profiler xdebug.profile_output_dir=/tmp ; output directory xdebug.profile_output_name=cachegrind.out.%p
  53. 53. 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?
  54. 54. VIEWING PROFILE KCacheGrind MacCallGrind WinCacheGrind Carica CacheGrind
  55. 55. PROFILING DEMO
  56. 56. TASK sudo nano -w /etc/php.d/xdebug.ini remove ; 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
  57. 57. APD Lives in PECL Similar to XDebug Doesn’t require KCachegrind Still only PHP 4
  58. 58. APD apd_set_pprof_trace() to enable profiler pprof is a script to interpret the trace Outputs to apd.dumpdir
  59. 59. BRINGING IT TOGETHER Use profiler with benchmarks Profiling can be run on production sites Optimise slow code
  60. 60. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×