Commit eb691f58 authored by Jim Jagielski's avatar Jim Jagielski
Browse files

Optimize... create a struct to hold the worker status info

(need to align w/ set_params later on) and note when we
update timestamps

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1066607 13f79535-47bb-0310-9956-ffa450edef68
parent 8034d9d5
Loading
Loading
Loading
Loading
+10 −2
Changes for modules/proxy/mod_proxy.h: 10 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -254,6 +254,8 @@ struct proxy_conn_pool {
    proxy_conn_rec *conn;   /* Single connection for prefork mpm */
};

/* Keep below in sync with proxy_util.c! */

/* worker status bits */
#define PROXY_WORKER_INITIALIZED    0x0001
#define PROXY_WORKER_IGNORE_ERRORS  0x0002
@@ -276,6 +278,12 @@ struct proxy_conn_pool {
#define PROXY_WORKER_HOT_STANDBY_FLAG    'H'
#define PROXY_WORKER_FREE_FLAG           'F'

typedef struct wstat {
    unsigned int bit;
    char flag;
    const char *name;
} wstat;

#define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \
PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )

@@ -378,7 +386,7 @@ typedef struct {
    char      sticky[PROXY_BALANCER_MAX_STICKY_SIZE];          /* sticky session identifier */
    char nonce[APR_UUID_FORMATTED_LENGTH + 1];
    apr_interval_time_t timeout;  /* Timeout for waiting on free connection */
    apr_time_t      updated;    /* timestamp of last update */
    apr_time_t      wupdated;     /* timestamp of last change to workers list */
    proxy_balancer_method *lbmethod;
    int             max_attempts;     /* Number of attempts before failing */
    int             index;      /* shm array index */
@@ -398,7 +406,7 @@ struct proxy_balancer {
    int max_workers;              /* maximum number of allowed workers */
    const char *name;             /* name of the load balancer */
    const char *sname;            /* filesystem safe balancer name */
    apr_time_t      updated;    /* timestamp of last update */
    apr_time_t      wupdated;    /* timestamp of last change to workers list */
    apr_global_mutex_t  *mutex; /* global lock for updating lb params */
    void            *context;   /* general purpose storage */
    proxy_balancer_shared *s;   /* Shared data */
+7 −2
Changes for modules/proxy/mod_proxy_balancer.c: 7 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -700,6 +700,7 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
    proxy_server_conf *conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
    const char *userdata_key = "mod_proxy_balancer_init";
    ap_slotmem_instance_t *new = NULL;
    apr_time_t tstamp;

    /* balancer_post_config() will be called twice during startup.  So, only
     * set up the static data the 1st time through. */
@@ -720,7 +721,7 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
        return !OK;
    }

    
    tstamp = apr_time_now();
    /*
     * Go thru each Vhost and create the shared mem slotmem for
     * each balancer's workers
@@ -803,6 +804,9 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
            }
            balancer->slot = new;

            /* sync all timestamps */
            balancer->wupdated = balancer->s->wupdated = tstamp;

            /* now go thru each worker */
            workers = (proxy_worker **)balancer->workers->elts;
            for (j = 0; j < balancer->workers->nelts; j++, workers++) {
@@ -822,6 +826,7 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
                    ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "Cannot share worker");
                    return !OK;
                }
                worker->s->updated = tstamp;
            }
        }
        s = s->next;
@@ -1044,7 +1049,7 @@ static int balancer_handler(request_rec *r)
            ap_rputs("\n\n<table border='0' style='text-align: left;'><tr>"
                "<th>Worker URL</th>"
                "<th>Route</th><th>RouteRedir</th>"
                "<th>Factor</th><th>Set</th><th>Status</th>"
                "<th>Factor</th><th>Set</th><th align='center'>Status</th>"
                "<th>Elected</th><th>To</th><th>From</th>"
                "</tr>\n", r);

+34 −80
Changes for modules/proxy/proxy_util.c: 34 added lines, 80 removed lines.
Original line number Diff line number Diff line
@@ -44,6 +44,20 @@ typedef struct {
    const char   *proxy_auth;      /* Proxy authorization */
} forward_info;

/* Keep synced with mod_proxy.h! */
wstat wstat_tbl[] = {
    {PROXY_WORKER_INITIALIZED,   PROXY_WORKER_INITIALIZED_FLAG,   "Init "},
    {PROXY_WORKER_IGNORE_ERRORS, PROXY_WORKER_IGNORE_ERRORS_FLAG, "Ign "},
    {PROXY_WORKER_DRAIN,         PROXY_WORKER_DRAIN_FLAG,         "Drn "},
    {PROXY_WORKER_IN_SHUTDOWN,   PROXY_WORKER_IN_SHUTDOWN_FLAG,   "Shut "},
    {PROXY_WORKER_DISABLED,      PROXY_WORKER_DISABLED_FLAG,      "Dis "},
    {PROXY_WORKER_STOPPED,       PROXY_WORKER_STOPPED_FLAG,       "Stop "},
    {PROXY_WORKER_IN_ERROR,      PROXY_WORKER_IN_ERROR_FLAG,      "Err "},
    {PROXY_WORKER_HOT_STANDBY,   PROXY_WORKER_HOT_STANDBY_FLAG,   "Stby "},
    {PROXY_WORKER_FREE,          PROXY_WORKER_FREE_FLAG,          "Free "},
    {0x0, '\0', NULL}
};

/* Global balancer counter */
int PROXY_DECLARE_DATA proxy_lb_workers = 0;
static int lb_workers_limit = 0;
@@ -1371,7 +1385,6 @@ PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p,
    memset(bshared, 0, sizeof(proxy_balancer_shared));
    
    bshared->lbmethod = lbmethod;
    bshared->updated = apr_time_now();
    bshared->was_malloced = (do_malloc != 0);

    /* Retrieve a UUID and store the nonce for the lifetime of
@@ -1712,6 +1725,9 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
        /* recall that we get a ptr to the ptr here */
        runtime = apr_array_push(balancer->workers);
        *worker = *runtime = apr_palloc(p, sizeof(proxy_worker));   /* right to left baby */
        /* we've updated the list of workers associated with
         * this balancer *locally* */
        balancer->wupdated = apr_time_now();
    } else if (conf) {
        *worker = apr_array_push(conf->workers);
    } else {
@@ -2837,93 +2853,31 @@ ap_proxy_hashfunc(const char *str, proxy_hash_t method)
PROXY_DECLARE(apr_status_t) ap_proxy_set_wstatus(const char c, int set, proxy_worker *w)
{
    unsigned int *status = &w->s->status;
    char bit = toupper(c);
    switch (bit) {
        case PROXY_WORKER_INITIALIZED_FLAG :
            if (set)
                *status |= PROXY_WORKER_INITIALIZED;
            else
                *status &= ~PROXY_WORKER_INITIALIZED;
            break;
        case PROXY_WORKER_IGNORE_ERRORS_FLAG :
            if (set)
                *status |= PROXY_WORKER_IGNORE_ERRORS;
            else
                *status &= ~PROXY_WORKER_IGNORE_ERRORS;
            break;
        case PROXY_WORKER_DRAIN_FLAG :
            if (set)
                *status |= PROXY_WORKER_DRAIN;
            else
                *status &= ~PROXY_WORKER_DRAIN;
            break;
        case PROXY_WORKER_IN_SHUTDOWN_FLAG :
            if (set)
                *status |= PROXY_WORKER_IN_SHUTDOWN;
            else
                *status &= ~PROXY_WORKER_IN_SHUTDOWN;
            break;
        case PROXY_WORKER_DISABLED_FLAG :
            if (set)
                *status |= PROXY_WORKER_DISABLED;
            else
                *status &= ~PROXY_WORKER_DISABLED;
            break;
        case PROXY_WORKER_STOPPED_FLAG :
            if (set)
                *status |= PROXY_WORKER_STOPPED;
            else
                *status &= ~PROXY_WORKER_STOPPED;
            break;
        case PROXY_WORKER_IN_ERROR_FLAG :
            if (set)
                *status |= PROXY_WORKER_IN_ERROR;
            else
                *status &= ~PROXY_WORKER_IN_ERROR;
            break;
        case PROXY_WORKER_HOT_STANDBY_FLAG :
    char flag = toupper(c);
    wstat *pwt = wstat_tbl;
    while (pwt->bit) {
        if (flag == pwt->flag) {
            if (set)
                *status |= PROXY_WORKER_HOT_STANDBY;
                *status |= pwt->bit;
            else
                *status &= ~PROXY_WORKER_HOT_STANDBY;
            break;
        case PROXY_WORKER_FREE_FLAG :
            if (set)
                *status |= PROXY_WORKER_FREE;
            else
                *status &= ~PROXY_WORKER_FREE;
            break;
        default:
            return APR_EINVAL;
            break;
    }
                *status &= ~(pwt->bit);
            return APR_SUCCESS;
        }
        pwt++;
    }
    return APR_EINVAL;
}

PROXY_DECLARE(char *) ap_proxy_parse_wstatus(apr_pool_t *p, proxy_worker *w)
{
    char *ret = NULL;
    char *ret = "";
    unsigned int status = w->s->status;
    if (status & PROXY_WORKER_INITIALIZED)
        ret = apr_pstrcat(p, "Init ", NULL);
    else
        ret = apr_pstrcat(p, "!Init ", NULL);
    if (status & PROXY_WORKER_IGNORE_ERRORS)
        ret = apr_pstrcat(p, ret, "Ign ", NULL);
    if (status & PROXY_WORKER_DRAIN)
        ret = apr_pstrcat(p, ret, "Drn ", NULL);
    if (status & PROXY_WORKER_IN_SHUTDOWN)
        ret = apr_pstrcat(p, ret, "Shut ", NULL);
    if (status & PROXY_WORKER_DISABLED)
        ret = apr_pstrcat(p, ret, "Dis ", NULL);
    if (status & PROXY_WORKER_STOPPED)
        ret = apr_pstrcat(p, ret, "Stop ", NULL);
    if (status & PROXY_WORKER_IN_ERROR)
        ret = apr_pstrcat(p, ret, "Err ", NULL);
    if (status & PROXY_WORKER_HOT_STANDBY)
        ret = apr_pstrcat(p, ret, "Stby ", NULL);
    if (status & PROXY_WORKER_FREE)
        ret = apr_pstrcat(p, ret, "Free ", NULL);
    wstat *pwt = wstat_tbl;
    while (pwt->bit) {
        if (status & pwt->bit)
            ret = apr_pstrcat(p, ret, pwt->name, NULL);
        pwt++;
    }
    if (PROXY_WORKER_IS_USABLE(w))
        ret = apr_pstrcat(p, ret, "Ok ", NULL);
    return ret;