Ole Spaarmann
Ole Spaarmann

Reputation: 16749

Best practice to identify performance bottlenecks in a PHP/MySQL application (Drupal)

I took over an app based on a heavily modified version of Drupal. The last developer didn't do a good job. At least at first sight I saw a lot of monkey-patching and things you should never ever do (password files, called password.txt, in a public webfolder, etc.).

The app is incredibly slow. I guess it is caused by bad code (since it doesn't load large assets) and I guess it must be MySQL related - but I don't know for sure.

Since the app is not documented, what would be the best and fastest approach to look for bottlenecks? Are there any tools that could help me? Where should I start?

I pulled a version to run it locally on a Mac, maybe that makes things easier.

Upvotes: 2

Views: 1457

Answers (2)

Ole Spaarmann
Ole Spaarmann

Reputation: 16749

since I'm using MAMP I thought I share what I did to check the MySQL queries. Beware: Only do that for testing purposes. Or clean your log files regularly, they'll build up.

I edited the my.cnf for MySQL in MAMP and added the following lines in the Mysqld Section

# The MySQL server
[mysqld]

# Some other configuration will be here

# ADD THE FOLLOWING LINES
slow-query-log = 1
slow-query-log-file = /Applications/MAMP/logs/mysql_slow.log
long_query_time = 0.001
log-queries-not-using-indexes
general_log=1
general_log_file= /Applications/MAMP/logs/mysql_query.log
log = /Applications/MAMP/logs/mysql_sql.log

Then just cd into the /Applications/MAMP/logs/ folder and watch with

tail -f ./mysql_slow.log 

what is going down.

Upvotes: 0

Marek
Marek

Reputation: 7433

If you suspect mysql queries, turn on log-slow-queries in mysql and set long_query_time to low value, eg 0.010 seconds. Or you can turn query log for all queries:

general_log=1
general_log_file="query.log"

Then xdebug has profiling abilities.

Upvotes: 1

Related Questions