mirror of
https://github.com/apache/httpd.git
synced 2025-08-08 15:02:10 +03:00
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
This commit is contained in:
@@ -254,6 +254,8 @@ struct proxy_conn_pool {
|
|||||||
proxy_conn_rec *conn; /* Single connection for prefork mpm */
|
proxy_conn_rec *conn; /* Single connection for prefork mpm */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Keep below in sync with proxy_util.c! */
|
||||||
|
|
||||||
/* worker status bits */
|
/* worker status bits */
|
||||||
#define PROXY_WORKER_INITIALIZED 0x0001
|
#define PROXY_WORKER_INITIALIZED 0x0001
|
||||||
#define PROXY_WORKER_IGNORE_ERRORS 0x0002
|
#define PROXY_WORKER_IGNORE_ERRORS 0x0002
|
||||||
@@ -276,6 +278,12 @@ struct proxy_conn_pool {
|
|||||||
#define PROXY_WORKER_HOT_STANDBY_FLAG 'H'
|
#define PROXY_WORKER_HOT_STANDBY_FLAG 'H'
|
||||||
#define PROXY_WORKER_FREE_FLAG 'F'
|
#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 | \
|
#define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \
|
||||||
PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )
|
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 sticky[PROXY_BALANCER_MAX_STICKY_SIZE]; /* sticky session identifier */
|
||||||
char nonce[APR_UUID_FORMATTED_LENGTH + 1];
|
char nonce[APR_UUID_FORMATTED_LENGTH + 1];
|
||||||
apr_interval_time_t timeout; /* Timeout for waiting on free connection */
|
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;
|
proxy_balancer_method *lbmethod;
|
||||||
int max_attempts; /* Number of attempts before failing */
|
int max_attempts; /* Number of attempts before failing */
|
||||||
int index; /* shm array index */
|
int index; /* shm array index */
|
||||||
@@ -398,7 +406,7 @@ struct proxy_balancer {
|
|||||||
int max_workers; /* maximum number of allowed workers */
|
int max_workers; /* maximum number of allowed workers */
|
||||||
const char *name; /* name of the load balancer */
|
const char *name; /* name of the load balancer */
|
||||||
const char *sname; /* filesystem safe balancer name */
|
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 */
|
apr_global_mutex_t *mutex; /* global lock for updating lb params */
|
||||||
void *context; /* general purpose storage */
|
void *context; /* general purpose storage */
|
||||||
proxy_balancer_shared *s; /* Shared data */
|
proxy_balancer_shared *s; /* Shared data */
|
||||||
|
@@ -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);
|
proxy_server_conf *conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
|
||||||
const char *userdata_key = "mod_proxy_balancer_init";
|
const char *userdata_key = "mod_proxy_balancer_init";
|
||||||
ap_slotmem_instance_t *new = NULL;
|
ap_slotmem_instance_t *new = NULL;
|
||||||
|
apr_time_t tstamp;
|
||||||
|
|
||||||
/* balancer_post_config() will be called twice during startup. So, only
|
/* balancer_post_config() will be called twice during startup. So, only
|
||||||
* set up the static data the 1st time through. */
|
* 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;
|
return !OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tstamp = apr_time_now();
|
||||||
/*
|
/*
|
||||||
* Go thru each Vhost and create the shared mem slotmem for
|
* Go thru each Vhost and create the shared mem slotmem for
|
||||||
* each balancer's workers
|
* each balancer's workers
|
||||||
@@ -803,6 +804,9 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
|
|||||||
}
|
}
|
||||||
balancer->slot = new;
|
balancer->slot = new;
|
||||||
|
|
||||||
|
/* sync all timestamps */
|
||||||
|
balancer->wupdated = balancer->s->wupdated = tstamp;
|
||||||
|
|
||||||
/* now go thru each worker */
|
/* now go thru each worker */
|
||||||
workers = (proxy_worker **)balancer->workers->elts;
|
workers = (proxy_worker **)balancer->workers->elts;
|
||||||
for (j = 0; j < balancer->workers->nelts; j++, workers++) {
|
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");
|
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "Cannot share worker");
|
||||||
return !OK;
|
return !OK;
|
||||||
}
|
}
|
||||||
|
worker->s->updated = tstamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s = s->next;
|
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>"
|
ap_rputs("\n\n<table border='0' style='text-align: left;'><tr>"
|
||||||
"<th>Worker URL</th>"
|
"<th>Worker URL</th>"
|
||||||
"<th>Route</th><th>RouteRedir</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>"
|
"<th>Elected</th><th>To</th><th>From</th>"
|
||||||
"</tr>\n", r);
|
"</tr>\n", r);
|
||||||
|
|
||||||
|
@@ -44,6 +44,20 @@ typedef struct {
|
|||||||
const char *proxy_auth; /* Proxy authorization */
|
const char *proxy_auth; /* Proxy authorization */
|
||||||
} forward_info;
|
} 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 */
|
/* Global balancer counter */
|
||||||
int PROXY_DECLARE_DATA proxy_lb_workers = 0;
|
int PROXY_DECLARE_DATA proxy_lb_workers = 0;
|
||||||
static int lb_workers_limit = 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));
|
memset(bshared, 0, sizeof(proxy_balancer_shared));
|
||||||
|
|
||||||
bshared->lbmethod = lbmethod;
|
bshared->lbmethod = lbmethod;
|
||||||
bshared->updated = apr_time_now();
|
|
||||||
bshared->was_malloced = (do_malloc != 0);
|
bshared->was_malloced = (do_malloc != 0);
|
||||||
|
|
||||||
/* Retrieve a UUID and store the nonce for the lifetime of
|
/* 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 */
|
/* recall that we get a ptr to the ptr here */
|
||||||
runtime = apr_array_push(balancer->workers);
|
runtime = apr_array_push(balancer->workers);
|
||||||
*worker = *runtime = apr_palloc(p, sizeof(proxy_worker)); /* right to left baby */
|
*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) {
|
} else if (conf) {
|
||||||
*worker = apr_array_push(conf->workers);
|
*worker = apr_array_push(conf->workers);
|
||||||
} else {
|
} 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)
|
PROXY_DECLARE(apr_status_t) ap_proxy_set_wstatus(const char c, int set, proxy_worker *w)
|
||||||
{
|
{
|
||||||
unsigned int *status = &w->s->status;
|
unsigned int *status = &w->s->status;
|
||||||
char bit = toupper(c);
|
char flag = toupper(c);
|
||||||
switch (bit) {
|
wstat *pwt = wstat_tbl;
|
||||||
case PROXY_WORKER_INITIALIZED_FLAG :
|
while (pwt->bit) {
|
||||||
|
if (flag == pwt->flag) {
|
||||||
if (set)
|
if (set)
|
||||||
*status |= PROXY_WORKER_INITIALIZED;
|
*status |= pwt->bit;
|
||||||
else
|
else
|
||||||
*status &= ~PROXY_WORKER_INITIALIZED;
|
*status &= ~(pwt->bit);
|
||||||
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 :
|
|
||||||
if (set)
|
|
||||||
*status |= PROXY_WORKER_HOT_STANDBY;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
return APR_SUCCESS;
|
return APR_SUCCESS;
|
||||||
|
}
|
||||||
|
pwt++;
|
||||||
|
}
|
||||||
|
return APR_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PROXY_DECLARE(char *) ap_proxy_parse_wstatus(apr_pool_t *p, proxy_worker *w)
|
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;
|
unsigned int status = w->s->status;
|
||||||
if (status & PROXY_WORKER_INITIALIZED)
|
wstat *pwt = wstat_tbl;
|
||||||
ret = apr_pstrcat(p, "Init ", NULL);
|
while (pwt->bit) {
|
||||||
else
|
if (status & pwt->bit)
|
||||||
ret = apr_pstrcat(p, "!Init ", NULL);
|
ret = apr_pstrcat(p, ret, pwt->name, NULL);
|
||||||
if (status & PROXY_WORKER_IGNORE_ERRORS)
|
pwt++;
|
||||||
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);
|
|
||||||
if (PROXY_WORKER_IS_USABLE(w))
|
if (PROXY_WORKER_IS_USABLE(w))
|
||||||
ret = apr_pstrcat(p, ret, "Ok ", NULL);
|
ret = apr_pstrcat(p, ret, "Ok ", NULL);
|
||||||
return ret;
|
return ret;
|
||||||
|
Reference in New Issue
Block a user