You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Yann Ylavic <yl...@gmail.com> on 2015/03/03 17:36:41 UTC

KeepAliveTimeout per vhost for non-async MPMs

Hi,

the keep-alive timeout applied for sync MPMs (worker, prefork, 2.2.x)
is currently c->base_server->keep_alive_timeout, which implies this
"oddity" in the manual :

- docs/2.2/mod/core.html#keepalivetimeout: "In a name-based virtual
host context, the value of the first defined virtual host (the default
host) in a set of NameVirtualHost will be used. The other values will
be ignored."

- docs/2.4/mod/core.html#keepalivetimeout: "In a name-based virtual
host context, the value of the first defined virtual host best
matching the local IP and port will be used."

This makes it quite unusable in a named based virtual host context
(but for the first vhost).

I propose to simply :

Index: modules/http/http_core.c
===================================================================
--- modules/http/http_core.c    (revision 1663701)
+++ modules/http/http_core.c    (working copy)
@@ -179,6 +179,8 @@ static int ap_process_http_sync_connection(conn_re

     ap_update_child_status_from_conn(c->sbh, SERVER_BUSY_READ, c);
     while ((r = ap_read_request(c)) != NULL) {
+        apr_interval_time_t keep_alive_timeout =
+                                r->server->keep_alive_timeout;

         c->keepalive = AP_CONN_UNKNOWN;
         /* process the request if it was read without error */
@@ -215,7 +217,7 @@ static int ap_process_http_sync_connection(conn_re
             csd = ap_get_conn_socket(c);
         }
         apr_socket_opt_set(csd, APR_INCOMPLETE_READ, 1);
-        apr_socket_timeout_set(csd, c->base_server->keep_alive_timeout);
+        apr_socket_timeout_set(csd, keep_alive_timeout);
         /* Go straight to select() to wait for the next request */
     }
--
so that it works in any vhost.

I addressed this in mpm_event (async) with a different/event specific
patch in PR56226.
So the patch above would make things consistent with all MPMs.

Thoughts, objections?

Regards,
Yann.

Re: KeepAliveTimeout per vhost for non-async MPMs

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Mar 3, 2015 at 9:55 PM, Yann Ylavic <yl...@gmail.com> wrote:
> The other possibility is to create a server_config for http_module
> (which does not exist, yet), and store the flag there.

I have tested the attached patch which works and (I think) preverves
backward compatibility.
If KeepAliveTimeout is defined in a server it is used, otherwise it's
the one from c->base_server.

The only compatibility breakage I can think of is for KeepAliveTimeout
defined in non-first server which were previously ignored and now
taken into account, but it means that the admin either didn't know
about its setting being ignored, or had better remove it...

If that's fine I'll commit this version for sync MPMs and the one from
PR56226 for mpm_event.
I'm not sure event should use the same heuristic since the current
behaviour is to use the global timeout only, but probably for
consistency I could use an optional_fn to make keep_alive_timeout_set
visible from others.

Re: KeepAliveTimeout per vhost for non-async MPMs

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Mar 3, 2015 at 6:59 PM, Eric Covener <co...@gmail.com> wrote:
> On Tue, Mar 3, 2015 at 12:45 PM, Yann Ylavic <yl...@gmail.com> wrote:
>> OTOH it makes it clear that the keepalive timeout belongs to the
>> IP:port the request was received on, and not to the server for which
>> the latest request was handled on that IP:port.
>
>
> I think I documented the behavior, but just to get it on the books.
> What you say above is definitely the rationalization, but I think if
> we can remember the last servers keepalivetimeout (migration problems
> aside) I think it is better to use it.

OK, will commit the patches.

Regarding migration, we could apply the timeout only when it is
explicitely defined in the server (the ones ignored currently, per the
doc), and use base_server for others.
The easy thing to do that is to add a new keep_alive_timeout_set flag
to the conn_rec, but I guess this is not an easy struct to change to
help migration...
The other possibility is to create a server_config for http_module
(which does not exist, yet), and store the flag there.

Re: KeepAliveTimeout per vhost for non-async MPMs

Posted by Jim Jagielski <ji...@jaguNET.com>.
:)
> On Mar 3, 2015, at 12:59 PM, Eric Covener <co...@gmail.com> wrote:
> 
> On Tue, Mar 3, 2015 at 12:45 PM, Yann Ylavic <yl...@gmail.com> wrote:
>> OTOH it makes it clear that the keepalive timeout belongs to the
>> IP:port the request was received on, and not to the server for which
>> the latest request was handled on that IP:port.
> 
> 
> I think I documented the behavior, but just to get it on the books.
> What you say above is definitely the rationalization, but I think if
> we can remember the last servers keepalivetimeout (migration problems
> aside) I think it is better to use it.


Re: KeepAliveTimeout per vhost for non-async MPMs

Posted by Eric Covener <co...@gmail.com>.
On Tue, Mar 3, 2015 at 12:45 PM, Yann Ylavic <yl...@gmail.com> wrote:
> OTOH it makes it clear that the keepalive timeout belongs to the
> IP:port the request was received on, and not to the server for which
> the latest request was handled on that IP:port.


I think I documented the behavior, but just to get it on the books.
What you say above is definitely the rationalization, but I think if
we can remember the last servers keepalivetimeout (migration problems
aside) I think it is better to use it.

Re: KeepAliveTimeout per vhost for non-async MPMs

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Mar 3, 2015 at 5:36 PM, Yann Ylavic <yl...@gmail.com> wrote:
> This makes it quite unusable in a named based virtual host context
> (but for the first vhost).

OTOH it makes it clear that the keepalive timeout belongs to the
IP:port the request was received on, and not to the server for which
the latest request was handled on that IP:port.
If this is intended (probably since it is implemented like this), I'll
modify the patch for mpm_event in PR56226 to use the server's Timeout
for the write completion queue only, and use
c->base_server->keep_alive_timeout for the keepalive queue (instead of
the main server's KeepAliveTimeout).

Re: KeepAliveTimeout per vhost for non-async MPMs

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Mar 3, 2015 at 5:51 PM, Yann Ylavic <yl...@gmail.com> wrote:
> (this may not be expected though).

Indeed, some (many) modules seem to depend on c->base_server not
changing before and after ap_read_request().
c->base_server = r->server is probably a bad idea...

Re: KeepAliveTimeout per vhost for non-async MPMs

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Mar 3, 2015 at 5:36 PM, Yann Ylavic <yl...@gmail.com> wrote:
>
> I propose to simply :
>
> Index: modules/http/http_core.c
> ===================================================================
> --- modules/http/http_core.c    (revision 1663701)
> +++ modules/http/http_core.c    (working copy)
> @@ -179,6 +179,8 @@ static int ap_process_http_sync_connection(conn_re
>
>      ap_update_child_status_from_conn(c->sbh, SERVER_BUSY_READ, c);
>      while ((r = ap_read_request(c)) != NULL) {
> +        apr_interval_time_t keep_alive_timeout =
> +                                r->server->keep_alive_timeout;

Maybe would could even :
+        c->base_server = r->server;
here...

>
>          c->keepalive = AP_CONN_UNKNOWN;
>          /* process the request if it was read without error */
> @@ -215,7 +217,7 @@ static int ap_process_http_sync_connection(conn_re
>              csd = ap_get_conn_socket(c);
>          }
>          apr_socket_opt_set(csd, APR_INCOMPLETE_READ, 1);
> -        apr_socket_timeout_set(csd, c->base_server->keep_alive_timeout);
> +        apr_socket_timeout_set(csd, keep_alive_timeout);

and don't need this.

>          /* Go straight to select() to wait for the next request */
>      }
> --

Hence we could figure out the exact server from a given c everywhere
even with named based vhosts.
(this may not be expected though).