I was trying to optimize my new website performance, my configuration is wordpress running on ubuntu 11.04 1G VPS with nginx/php-fpm/mysql. I used page caching, browser caching to make it faster. But there is something I need to understand: when I run a speed test using different online tools or firebug, there is a bottleneck on the first GET request, it takes 3 or 4 seconds waiting for the first byte from the server. after this the website load speed is acceptable. To explain it in another way, if you open the site from firefox for example, you will see the status bar stuck on "Waiting for mydomain.com.." for 3 or 4 seconds. I want to understand what are the factors that controls this waiting time, and recommendations for optimizing.
2 Answers
The delay in waiting for the first byte from the server could be one of a number of different things, including:
- Delay in DNS lookups
- Delay in server initiating a TCP session
- Delay in server sending request to server
- Delay in server sending back data once the request has been received.
Chrome's dev tools usually tells you which of these is the actual bottleneck, and only some of these are necessarily caused by server settings. I would find out which of these is causing the delay and work to resolve that.
Assuming you have no DNS, latency or bandwidth issues it sounds like the server might be taking a long time to generate the page output, either because it is overworked or because the application is just doing a lot and taking its time to render the page. Wordpress is known for being fairly chatty with databases (I've seen wordpress homepages make 500+ db queries before now), so I'd look to get one of the many php-profiling plugins and investigate if the application is generating the page in an acceptable amount of time. If the application is performant and the server still doesn't serve up the queries in a timely way, then that points more to a webserver configuration or server load issue.
Are you using the proxy features of nginx? nginx can buffer the response from the true server and then relay it to the client, so you may be seeing the delay from the buffering, if you have it enabled.
-
-
-
-
I play w/the proxy_pass, not fastcgi_pass, but looking at the wiki I'd say they follow the same rules, as they both can use the backend directive too. So take a look for some of the buffering options of fast_cgi and see if you can turn it off, not sure if you can.– WaldenLJun 5, 2012 at 18:37