Animal Rights
Animal Rights

Reputation: 9397

How do Apache connections work?

Do Apache connections close immediately after a server serves the web page?

Also, if you are hosting all your static assets (JS, CSS, images, etc) on the same server as your site, how does that affect Apache connections?

Upvotes: 0

Views: 6108

Answers (2)

Colin 't Hart
Colin 't Hart

Reputation: 7729

  1. Whether or not Apache closes a connection immediately after serving a page depends on

    1. whether the client requests it with a Connection: Keep-Alive header.
    2. the setting of the KeepAlive and KeepAliveTimeout parameters. See http://httpd.apache.org/docs/2.2/mod/core.html#keepalive
  2. All types of content use the same 'pool' of connections.

Good question: because all content uses the same KeepAlive settings, you may wish to setup different servers to handle different types of content.

--

For your next question:

  1. MaxKeepAliveRequests is documented on the same page: http://httpd.apache.org/docs/2.2/mod/core.html#maxkeepaliverequests

It's the total number of requests a client can make on one "kept alive connection". If you have lots of server resources you should keep it high. Or you can lower it to send clients away and give someone else a turn if you have low server resources or many clients. Don't forget that after the last request from the client the server will still wait "KeepAliveTimeout" seconds before closing the connection and making that worker available for another client.

  1. MaxRequestsPerChild is documented here: http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxrequestsperchild

It's the number of client requests (and individual requests over a kept-alive connection count for 1 each still) before the child server process will die. Different MPMs (ie Apache backends developed specifically for individual platforms that implement these child server processes) behave differently:

  • threaded MPMs have a default of 0 = never die as all threads share the same memory space anyway.
  • For an MPM using individual child processes it makes more sense to allow a child to die off every so often (potentially cleaning up server resources and memory leaks, if any).

Upvotes: 3

Mike Brant
Mike Brant

Reputation: 71384

The answer to your question is maybe. The connection might stay open depending on your KeepAlive settings. If you turn KeepAlive off altogether, then the connection will close after the request is satisfied. If you have KeepAlive on (which is more typical), then the connection will be maintained for some configurable amount of time waiting form another request from the client to which the connection is allocated.

Whether the request is for a dynamically-generated page or for static content does not really matter with regards to this behavior, however you would end up reusing the connections that the browser has established when downloading the static content from the server in the case where KeepAlive is on. This could provide better performance in that you don't have the overhead of re-establishing the connection for every single request.

Here is a link to a good article regarding consideration for using KeepAlive

http://abdussamad.com/archives/169-Apache-optimization:-KeepAlive-On-or-Off.html

Upvotes: 2

Related Questions