Debugging and Profiling Symfony Apps

43
Debugging and Profiling symfony applications by Alvaro Videla Wednesday, February 17, 2010

description

Slides for the Debugging and Profiling Symfony Apps from #sflive2010 by Alvaro Videla

Transcript of Debugging and Profiling Symfony Apps

Page 1: Debugging and Profiling Symfony Apps

Debugging and Profiling symfony applications

by Alvaro VidelaWednesday, February 17, 2010

Page 2: Debugging and Profiling Symfony Apps

About Me

• Lead Developer at TheNetCircle.com

• Creator of FireSymfony

• Twitter: @old_sound

• Blog: http://obvioushints.blogspot.com/

Wednesday, February 17, 2010

Page 3: Debugging and Profiling Symfony Apps

About Me

• Lead Developer at TheNetCircle.com

• Creator of FireSymfony - 16.000 downloads

• Twitter: @old_sound

• Blog: http://obvioushints.blogspot.com/

Wednesday, February 17, 2010

Page 4: Debugging and Profiling Symfony Apps

About our symfony site

• 2.000.000+ members

• 250.000+ logins/day

• 300.000+ private messages/day

• 14.000 req/min in the top 6 actions

Wednesday, February 17, 2010

Page 5: Debugging and Profiling Symfony Apps

Let’s talk about:

• Debugging Tools

• Profiling Tools

• Benchmarking Tools

• Live Site Metrics

Wednesday, February 17, 2010

Page 6: Debugging and Profiling Symfony Apps

Symfony Tools

Wednesday, February 17, 2010

Page 7: Debugging and Profiling Symfony Apps

Loggers

Wednesday, February 17, 2010

Page 8: Debugging and Profiling Symfony Apps

sfFileLogger

• logs per controller & environment

• very useful for development

• Prod, disable or set level: err

Wednesday, February 17, 2010

Page 9: Debugging and Profiling Symfony Apps

There’s a lot of information on the logs

• Cache hits

• Cache misses

• Number of Database Queries

Wednesday, February 17, 2010

Page 10: Debugging and Profiling Symfony Apps

AWK

• Extract information using AWK

• use: /(M|m)atch route/

http://gist.github.com/271034

Wednesday, February 17, 2010

Page 11: Debugging and Profiling Symfony Apps

Problems of this approach

• Hard to use with several servers

• Require to ssh and inspect logs in each of the servers

• Hard to visualize data in context

Wednesday, February 17, 2010

Page 12: Debugging and Profiling Symfony Apps

Next Step

A Centralized Logger

Wednesday, February 17, 2010

Page 13: Debugging and Profiling Symfony Apps

Sample Use Case

• CouchDB backend

• One Server collecting logs from 28 PHP machines

• 15 million logs in the first week

Wednesday, February 17, 2010

Page 14: Debugging and Profiling Symfony Apps

A Centralized Logger

Wednesday, February 17, 2010

Page 15: Debugging and Profiling Symfony Apps

5 minute How To

A Redis Logger

http://github.com/videlalvaro/avRedisLoggerPlugin

Wednesday, February 17, 2010

Page 16: Debugging and Profiling Symfony Apps

Logger Roadmap

Wednesday, February 17, 2010

Page 17: Debugging and Profiling Symfony Apps

Timers

Wednesday, February 17, 2010

Page 18: Debugging and Profiling Symfony Apps

sfTimer

• Easy to use

• Integrated with symfony debug tools

Wednesday, February 17, 2010

Page 19: Debugging and Profiling Symfony Apps

Using Timers

Wednesday, February 17, 2010

Page 20: Debugging and Profiling Symfony Apps

Problems of this approach

• Require to modify the code to add timers

• Only provides execution time information

• Best suited to run in dev mode

Wednesday, February 17, 2010

Page 21: Debugging and Profiling Symfony Apps

Next Step

Profile with XHProf

Wednesday, February 17, 2010

Page 22: Debugging and Profiling Symfony Apps

XHProf• C extension for PHP

• Open sourced by Facebook

• Hierarchical Profiler

• Extracts:

- Walltime

- Memory Usage

Wednesday, February 17, 2010

Page 23: Debugging and Profiling Symfony Apps

XHProf Web Interface• Single Runs

• Compare Runs

• Aggregate Runs

• Sort runs by:

- Number Function Calls

- Memory Usage

- Walltime

Wednesday, February 17, 2010

Page 24: Debugging and Profiling Symfony Apps

5 minute How To

Adding XHProf to an index.php

http://gist.github.com/300261

Wednesday, February 17, 2010

Page 25: Debugging and Profiling Symfony Apps

symfony 1.0 vs. symfony 1.2*

*sfCompat10Plugin enabled

Wednesday, February 17, 2010

Page 26: Debugging and Profiling Symfony Apps

@old_sound: “Hello World!” Benchmarks Considered Evil! #sflive2010

1 second ago from Cité Universitaire Internationale

Wednesday, February 17, 2010

Page 27: Debugging and Profiling Symfony Apps

symfony 1.0 vs. symfony 1.2*

*sfCompat10Plugin enabled

Wednesday, February 17, 2010

Page 28: Debugging and Profiling Symfony Apps

symfony 1.0 vs. symfony 1.2*

*sfCompat10Plugin enabled

Wednesday, February 17, 2010

Page 29: Debugging and Profiling Symfony Apps

Tsung• High performance benchmarking framework

• Open Source

• Distributed benchmarking

• Can simulate user sessions

• Records and replay browser interaction

• Can benchmark HTTP, MySQL, Ejabberd

• Can be extended

Wednesday, February 17, 2010

Page 30: Debugging and Profiling Symfony Apps

Tsung Sessions

• Arrival Phase

• Duration

• Amount of Users

• Meassure system load

Wednesday, February 17, 2010

Page 31: Debugging and Profiling Symfony Apps

Tsung

Wednesday, February 17, 2010

Page 32: Debugging and Profiling Symfony Apps

Metrics

Wednesday, February 17, 2010

Page 33: Debugging and Profiling Symfony Apps

Metrics

Live Site Metrics With Graphite

Wednesday, February 17, 2010

Page 34: Debugging and Profiling Symfony Apps

Graphite

• “... a highly scalable real-time graphing system”

• Open Source

• Text Protocol

• Awesome Graphics Capabilities

http://graphite.wikidot.com/

Wednesday, February 17, 2010

Page 35: Debugging and Profiling Symfony Apps

Graphite in Action

Wednesday, February 17, 2010

Page 36: Debugging and Profiling Symfony Apps

We use it for• System Load Comparisons

• APC Stats

• Memcache Stats

• Number of Online Users

• AVG module/action request time

• AVG module/action memory usage

• module/action request count

Wednesday, February 17, 2010

Page 37: Debugging and Profiling Symfony Apps

symfony 1.0 vs. symfony 1.2*

*sfCompat10Plugin enabled

Wednesday, February 17, 2010

Page 38: Debugging and Profiling Symfony Apps

symfony 1.0 vs. symfony 1.2*

*sfCompat10Plugin enabled

Wednesday, February 17, 2010

Page 39: Debugging and Profiling Symfony Apps

5 minute How To

Adding Graphite to an index.php

http://gist.github.com/300265

Wednesday, February 17, 2010

Page 40: Debugging and Profiling Symfony Apps

Roadmap

•Write C PHP Extension

• Take advantage of Request Life Cycle

• Ease metric recording

Wednesday, February 17, 2010

Page 41: Debugging and Profiling Symfony Apps

Links

• http://www.rabbitmq.com/

• http://tsung.erlang-projects.org/

• http://graphite.wikidot.com/

• http://pecl.php.net/package/xhprof

Wednesday, February 17, 2010

Page 42: Debugging and Profiling Symfony Apps

Questions?

Wednesday, February 17, 2010

Page 43: Debugging and Profiling Symfony Apps

Thanks!

Alvaro Videla

http://twitter.com/old_sound

Wednesday, February 17, 2010