Random Profiling Tips And Tools for your LAMP stack
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
The slow log ● Logging to a table is also possible: log_output = TABLE
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?
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.
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.
usleep(1000); // 0.001s
Yii Notice the difference?
Sometimes XDebug is weird Laravel
Try XHProf ● Doesn't slow down execution time as much as XDebug ● Profiling log file ~10 times smal er ● 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
Blackfire ● More or less same thing as XDebug and XHProf, but... ● Works in your browser ● Nicer UI ● May be also usable on production
XDebug can colorize your var_dump() xdebug.cli_color = 1
Perf Record system resource usage overtime perf record -a -g sleep 10 # record system for 10s perf report # display report
Munin ● Spot problems before they become critical ● Plugins to monitor virtuall y anything: – Drupal – Apache – PHP – Joomla – Reddit Karma ( seriously ) ● Distributed. Generate logs for all your servers. ● Demo: http://demo.munin-monitoring.org/