Discussion:
[PATCH] Goofing with proxy load balancing
Bill Stoddard
2003-07-23 03:27:49 UTC
Permalink
Here is some nasty nasty code but it works well enough for me to test
some ideas. I'll refine it as I have time.

Quick overview of the implementation:
This code uses a single optional hook, the load_balance hook, which is
defined by mod_proxy, implemented in mod_proxy_lb.c and is called by
ap_proxy_http_create_connection in proxy_http.c. The hook takes three
input arguments:
request_rec *r,
char *load_balancer_module_id,
r->unparsed_uri,

and returns a 'trylist'. The trylist contains pointers to a couple of
callback functions defined by the lb module identified by
'load_balancer_module_id'. One callback is to fetch an ip address
(actually a proxy_conn_t*) to use to route a request. The other callback
is to report a failure to establish a connection with that
proxy_conn_t). The trylist also contains a void * pointer to an opaque
datatype specific to a particular load_balancer module. I did it this
way to reduce unnecessary coupling between the load balancers and
mod_proxy/proxy_http.

mod_proxy_lb.c is a braindead round robin router. Hopefully it is
sufficient to demonstrate where I'm heading... Load balancer modules can
be arbitraily complex in how they decide to route requests.

To use...
1. apply the patch from directory modules/proxy

2. add mod_proxy_lb.c to your compile environment (compile it as
loadable module)

3. Update httpd.conf with something like this:

LoadModule proxy_lb_module modules/mod_proxy_lb.so
<IfModule mod_proxy_lb.c>
LBServerCluster cluster1 http://downstreamserver1:port
LBServerCluster cluster1 http://downstreamserver2:port
LBProxyPass /file500.html cluster1
LBProxyPass /snoop cluster1
</IfModule>

Where 'downstreamserver#' is the name of a backend system to route
requests to. 'cluster1' is the name of a logical group of backend
machines pointed to by LBProxyPass directives (which are coded exactly
like ProxyPass directives, except the 'real' name is replaced by a
symbol representing the backend cluster.)

If I send a request for /snoop, the request will be routed to the
servers defined in LBServerCluster in the order they appear in the
config file. Rerouting to the next server will only occur if either the
DNS lookup or connection establishment to the server fails. Simple
failure to find a resource on the target server will not cause a reroute.

My fingers are tired of typing so here is the patch. Comments welcome.

Bill
Graham Leggett
2003-07-23 11:40:03 UTC
Permalink
Post by Bill Stoddard
This code uses a single optional hook, the load_balance hook, which is
defined by mod_proxy, implemented in mod_proxy_lb.c and is called by
ap_proxy_http_create_connection in proxy_http.c.
One more quick thing - the connection hook should not be in
proxy_http.c, as the functionality is then limited to the HTTP proxy
module only.

The hook should be in mod_proxy.c, or in proxy_util.c, and so be
accessible to proxy_ftp and proxy_connect also.

Regards,
Graham
--
-----------------------------------------
***@sharp.fm "There's a moon
over Bourbon Street
tonight..."
Graham Leggett
2003-07-23 11:36:31 UTC
Permalink
Hi,
Post by Bill Stoddard
This code uses a single optional hook, the load_balance hook, which is
defined by mod_proxy, implemented in mod_proxy_lb.c and is called by
ap_proxy_http_create_connection in proxy_http.c.
Is it possible to call this hook something more general than "load
balancing", as load balancing is just one possible function of this.

Also, something that would be really useful is for a "load
balancer/backhand" module is the ability for the module hook to return
DECLINED:

Say for example a stateful module that watches JSESSIONID and passes all
common requests to the same backend server, might choose to decline to
perform, based on the cookie being missing, etc. Then, the next module
in line (eg simple-round-robin) gets a go.

There would have to be a second hook in there, after the request is
complete, so that the stateful module could see JSESSIONID when it was
set the first time.

Thoughts?

Regards,
Graham
--
-----------------------------------------
***@sharp.fm "There's a moon
over Bourbon Street
tonight..."
Loading...