0

I've just moved two sites to a new server. They are both similar, Drupal based sites. One loads normally (1-3 seconds) but the other takes up to 12-15 seconds. After much logging and measuring I've found that most of the delay is waiting for a response from the server. That is, when I load the page in the browser, it takes up to 10 seconds for Apache on the server to get the request. I've double checked the DNS entries but cannot find anything wrong.

How can I narrow down what the cause of this may be?

jalal
  • 153
  • 6
  • try downloading a file using SCP or another protocol directly (not using apache/mysql) and see if there's a difference. – LinuxDevOps Apr 01 '14 at 13:42
  • FTP, SCP all work fine. You have prompted me to try a static HTML file and that also is immediate, as is an empty PHP file, so it seems Drupal, Apache or MySQL is involved somewhere. – jalal Apr 01 '14 at 15:12
  • 1
    Mysql would be suspect. Try a test PHP file that connects to the database and returns a simple SELECT query. – LinuxDevOps Apr 01 '14 at 15:18
  • You can enable Slow queries log in MySQL, and see if there are any long executing queries. Or, you could check the MySQL processlist while the long-running request is running to see if there are any long-running queries. – Tero Kilkanen Apr 01 '14 at 17:07
  • I didn't find any slow queries. And I can't find any long running requests. Testing a Drupal install with a simple database SELECT is not so straightforward, but it seems to return quite fast, so I'm tending to think I have some queries without indexes or something. – jalal Apr 01 '14 at 17:33

1 Answers1

0

You'll want to use something that can peer inside the request for clues. The Devel module allows you to see a breakdown of queries that are being run and how long they take. Other tools, like XHProf, give you even deeper insights.

Ultimately, "waiting for response" is a red herring. What it means doesn't line up with the intuitive leap you appear to have made. In this case, it's not that the server is delaying its response, it's that the server is preparing its response. Therefore, your job is to find out what's taking the server so long.

Common causes of this that I've seen in just the last few weeks:

  • Dead memcached/redis hosts defined in settings.php (especially on unreachable RFC1918 subnets)
  • Runaway MySQL queries
  • MySQL server specified as a hostname with a slow DNS server
  • MySQL server configured to look up client hostnames (i.e., no skip_name_resolve)
  • Cron hasn't run in a while, has a large backlog, and "poor man's cron" module enabled

But again, these are all shots in the dark; you'll want to instrument and proceed deductively, rather than SWAGing your way through this.

BMDan
  • 7,249
  • 2
  • 23
  • 34