Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Profiling tips and tools for your LAMP stack

Bf6729adaf5dd05bc0312b885c9d0e5f?s=47 dracony
December 02, 2014

Profiling tips and tools for your LAMP stack

Some hints for profiling your Linux, Apache (Nginx), PHP and MySQL stack.

Bf6729adaf5dd05bc0312b885c9d0e5f?s=128

dracony

December 02, 2014
Tweet

More Decks by dracony

Other Decks in Programming

Transcript

  1. Random Profiling Tips And Tools for your LAMP stack

  2. MySQL

  3. The usual start • Turn on slow query log: slow_query_log

    = 1 slow_query_log_file=”/var/log/mysql/slow.log” long_query_time = 1 • … and also log queries not using indexes: log_queries_not_using_indexes = 1 • … and if you use replication: log_slow_slave_statements = 1
  4. The slow log • Logging to a table is also

    possible: log_output = TABLE
  5. Parsing it • Mysqldumpslow: • • • https://code.google.com/p/mysql-log-filter/ • https://github.com/LeeKemp/mysql-slow-query-log-parser

  6. Narrowing down Obviously try EXPLAIN first: If the query had

    a usable index the result would be: But what if we have too many indexes?
  7. Persona toolkit • 32 tools for various things • pt-index-usage:

    – This tool connects to a MySQL database server, reads through a query log, and uses EXPLAIN to ask MySQL how it will use each query. When it is finished, it prints out a report on indexes that the queries didn’t use.
  8. Monitoring • Sadly, only a bunch of free tools =(

    • Profile SQL ( http://www.profilesql.com/features/ )
  9. PHP

  10. Use a ruler Adding a simple usleep() call when profiling

    will provide you with a reference point for easier visual comparison of generated graphs. The bigger the usleep() block appears the faster the application performs.
  11. CakePHP usleep(1000); // 0.001s

  12. Yii Notice the difference?

  13. Sometimes XDebug is weird WTF? Laravel

  14. Try XHProf • Doesn't slow down execution time as much

    as XDebug • Profiling log file ~10 times smaller • Memory profiling. With XDebug you have to generate a trace to get a memory profile. • Allows you to compare results from multiple runs • Sadly no KCacheGrind and the profiler output is not very pretty
  15. XHPROF

  16. Blackfire

  17. Blackfire • More or less same thing as XDebug and

    XHProf, but... • Works in your browser • Nicer UI • May be also usable on production
  18. Blackfire

  19. XDebug can colorize your var_dump() xdebug.cli_color = 1

  20. Linux

  21. Perf Record system resource usage overtime perf record -a -g

    sleep 10 # record system for 10s perf report # display report
  22. Perf

  23. Munin • Spot problems before they become critical • Plugins

    to monitor virtuallly anything: – Drupal – Apache – PHP – Joomla – Reddit Karma ( seriously ) • Distributed. Generate logs for all your servers. • Demo: http://demo.munin-monitoring.org/
  24. Munin

  25. Monitoring Nginx

  26. Monitoring Nginx

  27. Monitoring Apache

  28. Dracony github.com/dracony phpixie.com/blog @dracony_gimp dracony.org