httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruediger Pluem <rpl...@apache.org>
Subject Re: svn commit: r721987 - in /httpd/httpd/trunk: CHANGES modules/proxy/config.m4 modules/proxy/mod_lbmethod_heartbeat.c
Date Mon, 01 Dec 2008 19:37:03 GMT


On 12/01/2008 08:25 AM, pquerna@apache.org wrote:
> Author: pquerna
> Date: Sun Nov 30 23:25:11 2008
> New Revision: 721987
> 
> URL: http://svn.apache.org/viewvc?rev=721987&view=rev
> Log:
> Add a new module to read in the heartbeat file and do load balancing for
> mod_proxy based upon it.
> 
> Added:
>     httpd/httpd/trunk/modules/proxy/mod_lbmethod_heartbeat.c   (contents, props changed)
>       - copied, changed from r721944, httpd/httpd/trunk/modules/proxy/examples/mod_lbmethod_rr.c
> Modified:
>     httpd/httpd/trunk/CHANGES
>     httpd/httpd/trunk/modules/proxy/config.m4
> 

> Copied: httpd/httpd/trunk/modules/proxy/mod_lbmethod_heartbeat.c (from r721944, httpd/httpd/trunk/modules/proxy/examples/mod_lbmethod_rr.c)
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_lbmethod_heartbeat.c?p2=httpd/httpd/trunk/modules/proxy/mod_lbmethod_heartbeat.c&p1=httpd/httpd/trunk/modules/proxy/examples/mod_lbmethod_rr.c&r1=721944&r2=721987&rev=721987&view=diff
> ==============================================================================

> +
> +static proxy_worker *find_best_hb(proxy_balancer *balancer,
> +                                  request_rec *r)
>  {
> +    apr_status_t rv;
>      int i;
> +    apr_uint32_t openslots = 0;
>      proxy_worker *worker;
> +    hb_server_t *server;
> +    apr_array_header_t *up_servers;
>      proxy_worker *mycandidate = NULL;
> -    int checking_standby;
> -    int checked_standby;
> -    rr_data *ctx;
> -
> -    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
> -                 "proxy: Entering roundrobin for BALANCER %s (%d)",
> -                 balancer->name, (int)getpid());
> -    
> -    /* The index of the candidate last chosen is stored in ctx->index */
> -    if (!balancer->context) {
> -        /* UGLY */
> -        ctx = apr_pcalloc(r->server->process->pconf, sizeof(rr_data));
> -        balancer->context = (void *)ctx;
> -        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
> -                 "proxy: Creating roundrobin ctx for BALANCER %s (%d)",
> -                 balancer->name, (int)getpid());
> -    } else {
> -        ctx = (rr_data *)balancer->context;
> -    }
> -    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
> -                 "proxy: roundrobin index: %d (%d)",
> -                 ctx->index, (int)getpid());
> -
> -    checking_standby = checked_standby = 0;
> -    while (!mycandidate && !checked_standby) {
> -        worker = (proxy_worker *)balancer->workers->elts;
> +    apr_pool_t *tpool;
> +    apr_hash_t *servers;
>  
> -        for (i = 0; i < balancer->workers->nelts; i++, worker++) {
> -            if (i < ctx->index)
> -                continue;
> -            if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker))
)
> -                continue;
> -            if (!PROXY_WORKER_IS_USABLE(worker))
> -                ap_proxy_retry_worker("BALANCER", worker, r->server);
> -            if (PROXY_WORKER_IS_USABLE(worker)) {
> -                mycandidate = worker;
> -                break;
> +    lb_hb_ctx_t *ctx = 
> +        ap_get_module_config(r->server->module_config,
> +                             &lbmethod_heartbeat_module);
> +
> +    apr_pool_create(&tpool, r->pool);
> +
> +    servers = apr_hash_make(tpool);
> +
> +    rv = read_heartbeats(ctx->path, servers, tpool);
> +
> +    if (rv) {
> +        ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
> +                      "lb_heartbeat: Unable to read heartbeats at '%s'",
> +                      ctx->path);
> +        apr_pool_destroy(tpool);
> +        return NULL;
> +    }
> +
> +    up_servers = apr_array_make(tpool, apr_hash_count(servers), sizeof(hb_server_t *));
> +
> +    for (i = 0; i < balancer->workers->nelts; i++) {
> +        worker = &APR_ARRAY_IDX(balancer->workers, i, proxy_worker);
> +        server = apr_hash_get(servers, worker->hostname, APR_HASH_KEY_STRING);

Hm, the hash uses IP addresses as keys whereas worker->hostname could be name.

> +
> +        if (!server) {
> +            continue;
> +        }
> +
> +        if (!PROXY_WORKER_IS_USABLE(worker)) {
> +            ap_proxy_retry_worker("BALANCER", worker, r->server);
> +        }
> +
> +        if (PROXY_WORKER_IS_USABLE(worker)) {
> +            server->worker = worker;
> +            if (server->seen < 10) {

Hm. Hardcoded 10. This seems to be ugly.

> +                openslots += server->ready;
> +                APR_ARRAY_PUSH(up_servers, hb_server_t *) = server;
>              }
>          }

Regards

RĂ¼diger

Mime
View raw message