Nginx – WordPress website with extremely slow response (only for the first request)

amazon ec2nginxWordpress

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 23.21.171.95... connected
* Connected to rohitnair.info (23.21.171.95) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.12.9.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
> Host: rohitnair.info
> Accept: */*
> 

long wait

[response]

* 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!

Best Answer

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.

Related Topic