caching for cash: benchmarking and profiling

Post on 01-Sep-2014

3.900 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

CACHING FOR CASH - BENCHMARKING

Scott MacVicar + Helgi Þormar Þorbjörnssonphp|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 linearly

REQUIREMENTS

Same hardware configuration

Same server configuration

Same network interface speed (100mbps)

Basically your “staging server”

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

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 downloads a file

SINGLE PAGE

Page Image ImageKeep Alive

TWO PAGE VISITS

Page Image ImageKeep Alive

Page Image ImageKeep Alive

30 secslater

TWO PAGE VISITS AND DOWNOAD

Page Image ImageKeep Alive

Page Image ImageKeep Alive

30 secslater

ISO

15 secslater

SETUP A PROFILE

enable keepalive

use the relative times output format

check for 200 OK

RUNNING FLOOD

flood <configuration.xml> > output.file

anaylze-relative output.file

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

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

SIEGE

Provides functionality of Apache Bench and Flood

Supports GET and POST with a simple syntax

Benchmark and Internet mode

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

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

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 memory usage

PROFILING TOOLS

XDebug

apd

XDEBUG

Debugger

Code Coverage

Memory and Executon time

XDEBUG PROTECTIONS

Stack overflow in PHP

Infinite Recursion

ERROR MESSAGE HELPING

MORE ERROR MESSAGE HELPING

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

EXECUTION TRACE

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.

CODE COVERAGE

Finds unexecuted code

xdebug_start_code_coverage()

xdebug_get_code_coverage()

xdebug_stop_code_coverage()

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

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?

VIEWING PROFILE

KCacheGrind

MacCallGrind

WinCacheGrind

Carica CacheGrind

PROFILING DEMO

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

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.org/docs/

http://www.joedog.org

top related