I've a weird issue with my wordpress website ( http://rohitnair.info/) . The "first request" takes ages to respond. Any subsequent responses behave normally. Things I've observed while debugging

  • Clearing the browser cache and reloading works fine and the page loads fast enough
  • Clearing the cookies and reloading reproduces the issue.
  • nslookup etc do not take time (so ruling out DNS lookup issues)
  • Issue seems to be reproducible from other machines/networks (so ruling out local machine/network issues)
  • Nothing in mysql slow query logs

I thus define "first request" in this context as a request with no cookies set for the domain. Another easy way to reproduce this issue is to use curl and not send any cookies. This is the output of curl -v

$ time curl -v rohitnair.info
* About to connect() to rohitnair.info port 80 (#0)
* Trying connected
* Connected to rohitnair.info ( port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/ zlib/1.2.3 libidn/1.18 libssh2/1.2.2
> Host: rohitnair.info
> Accept: */*

long wait


* Connection #0 to host rohitnair.info left intact
* Closing connection #0

real    1m0.518s
user    0m0.003s
sys 0m0.011s

As can be seen, the server takes more than a minute to return the response.

The stack is wordpress + nginx and hosted on Amazon EC2 micro instance. I've also noticed that the request does not show up in the nginx access log till the response is served or the request is cancelled (not sure if this is expected behavior) I'm completely lost as to what could be causing this issue. Any help would be much appreciated!

  • You haven't ruled out DNS just yet, because nslookup is not the same as nginx or PHP performing the request. Watch DNS requests out to see if any of them are patently silly. – Joel E Salas May 2 '12 at 5:04
  • To further eliminate DNS/network issues, try: curl -v --header "Host: rohitnair.info" and run it from the server with curl -v --header "Host: rohitnair.info" As for cookies - see if you can delete them individually and decide if one (e.g. the session cookie) is making the difference. (Requiring a new session would require a disk write to your session path, on a slow disk (or some other issue) there could be a delay, but reads would be cached - seems unlikely though). – cyberx86 May 2 '12 at 5:13

You haven't ruled out DNS just yet, because nslookup is not the same as nginx or PHP performing the request. Watch DNS requests out to see if any of them are patently silly.

Whenever anything is unexpectedly slow (HTTP request, initial ssh connection, etc), but only slow at first, it's generally a reverse DNS request that's timing out.

  • Fair point, DNS lookups from the server could be the issue. How do I check on outgoing requests though? Is there any specific tool I could use? – Rohit Nair May 2 '12 at 6:06
  • 1
    Yes, tcpdump allows you to see if the server does a reverse DNS lookup on every request: tcpdump -n port 53. – Oliver May 2 '12 at 6:12
  • 1
    Thanks for the command, I was exploring tcpdump as well. And wow, that really seems to be relevant. I noticed that whenever I clear my cookies, there's a bizarre lookup that happens (output of tcpdump below) 07:01:58.836219 IP > 19169+ A? f528764d624db129b32c21fbca0cb8d6.com Just as a temporary hack, I pointed this random URL (f528764d624db129b32c21fbca0cb8d6.com) to in my /etc/hosts file and it fixed the issue! Any insights as to what this could be? Is this wordpress/ec2 specific by any chance? I'm really curious to know! – Rohit Nair May 2 '12 at 7:17
  • Does the DNS lookup change? What plugins are you using? – Joel E Salas May 2 '12 at 7:21
  • The random URL I mentioned above no longer shows up in the tcpdump output (because it gets resolved locally via /etc/hosts I guess) My WP plugins - Akismet, Jetpack, All in one SEO pack, SyntaxHighlighter, Wordpress Importer and WP-phpMyAdmin – Rohit Nair May 2 '12 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.