13

I am using nginx along with php-fpm to server a busy mysql-based site. Currently I am using keepalive_timeout = 5, however I have no clear idea about how to optimally adjust it. So appreciate your hints.

1 Answer 1

10

What do you need to adjust it to do, or rather: are you seeing any problems with having it set how you do?

There isn't a good one-size-fits-all answer; if most client browsers are able to load all the resources on a page in 5 seconds then 5 seconds is just fine, but it completely depends on your application's needs - if your nginx server were serving as a reverse proxy for Exchange ActiveSync, for instance, you'd want it cranked all the way up to half an hour.

5
  • Well, I am trying to minimize the server load (which is quite high at pick times), and I guess optimizing keepalive_timeout can partially contribute to this goal. Apart from that it is just healthy curiosity :)
    – alfish
    Nov 16, 2011 at 22:29
  • 1
    Sure - so, pretty much "as low as possible without kicking most clients off before they load the page" - so if your pages load in under a second for most of your clients, then a 1 second timeout will be fine. But, unless your timeout is much, much higher than 5 seconds, then it's unlikely that it's a major cause of server load. Nov 16, 2011 at 22:34
  • That's the tricky point. How can I determine the page load time, given the difference in pages load time (some are heavier than others),visitor's connection speeds, etc.
    – alfish
    Nov 16, 2011 at 22:40
  • Just ballpark it. A few seconds one way or another is unlikely to make any substantial difference in load, so feel free to estimate high - but then again, a new build of a TCP connection (even with an SSL handshake, if applicable) for a slow loading client isn't going to make a large difference in their overall loading speed. Nov 16, 2011 at 22:46
  • 1
    @ShaneMadden, that 5 seconds are not the lifespan of the connection, but only a timeout during which server waits for another request up to keepalive_requests. So it is not important how much time it takes for the full page to load, just for the html until browser start fetching images/css... BTW the max. time connection is kept open is almost keepalive_timeout*keepalive_requests
    – Marki555
    Jan 30, 2014 at 10:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .