#define MAX(x,y) ((x) >= (y) ? (x) : (y))
#endif
+/* Global balancer counter */
+static int lb_workers_limit = 0;
+
+/* return the sizeof of one lb_worker in scoreboard. */
+static int ap_proxy_lb_worker_size(void)
+{
+ return sizeof(proxy_worker_stat);
+}
+
+
+
/*
* A Web proxy module. Stages:
*
static const char *const aszPred[] = { "mpm_winnt.c", NULL};
APR_REGISTER_OPTIONAL_FN(ap_proxy_lb_workers);
+ APR_REGISTER_OPTIONAL_FN(ap_proxy_lb_worker_size);
/* handler */
ap_hook_handler(proxy_handler, NULL, NULL, APR_HOOK_FIRST);
/* filename-to-URI translation */
proxy_worker *worker,
server_rec *s)
{
- lb_score *score = NULL;
+ proxy_worker_stat *score = NULL;
if (PROXY_WORKER_IS_INITIALIZED(worker)) {
/* The worker share is already initialized */
}
/* Get scoreboard slot */
if (ap_scoreboard_image) {
- score = ap_get_scoreboard_lb(worker->id);
+ score = (proxy_worker_stat *) ap_get_scoreboard_lb(worker->id);
if (!score) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
"proxy: ap_get_scoreboard_lb(%d) failed in child %" APR_PID_T_FMT " for worker %s",
}
}
if (!score) {
- score = apr_pcalloc(conf->pool, sizeof(proxy_worker_stat));
+ score = (proxy_worker_stat *) apr_pcalloc(conf->pool, sizeof(proxy_worker_stat));
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"proxy: initialized plain memory in child %" APR_PID_T_FMT " for worker %s",
getpid(), worker->name);
}
- worker->s = (proxy_worker_stat *)score;
+ worker->s = score;
/*
* recheck to see if we've already been here. Possible
* if proxy is using scoreboard to hold shared stats
static APR_OPTIONAL_FN_TYPE(ap_proxy_lb_workers)
*pfn_proxy_lb_workers;
+static APR_OPTIONAL_FN_TYPE(ap_proxy_lb_worker_size)
+ *pfn_proxy_lb_worker_size;
struct ap_sb_handle_t {
int child_num;
int thread_num;
};
-static int server_limit, thread_limit, lb_limit;
+static int server_limit, thread_limit, lb_limit, worker_size;
static apr_size_t scoreboard_size;
/*
else
lb_limit = 0;
+ if (!pfn_proxy_lb_worker_size)
+ pfn_proxy_lb_worker_size = APR_RETRIEVE_OPTIONAL_FN(ap_proxy_lb_worker_size);
+ if (pfn_proxy_lb_worker_size)
+ worker_size = pfn_proxy_lb_worker_size();
+ else
+ worker_size = sizeof(lb_score);
+
scoreboard_size = sizeof(global_score);
scoreboard_size += sizeof(process_score) * server_limit;
scoreboard_size += sizeof(worker_score) * server_limit * thread_limit;
- if (lb_limit)
- scoreboard_size += sizeof(lb_score) * lb_limit;
+ if (lb_limit && worker_size)
+ scoreboard_size += worker_size * lb_limit;
return scoreboard_size;
}
ap_scoreboard_image->servers[i] = (worker_score *)more_storage;
more_storage += thread_limit * sizeof(worker_score);
}
- if (lb_limit) {
- ap_scoreboard_image->balancers = (lb_score *)more_storage;
- more_storage += lb_limit * sizeof(lb_score);
+ if (lb_limit && worker_size) {
+ ap_scoreboard_image->balancers = (void *)more_storage;
+ more_storage += lb_limit * worker_size;
}
ap_assert(more_storage == (char*)shared_score + scoreboard_size);
ap_scoreboard_image->global->server_limit = server_limit;
sizeof(worker_score) * thread_limit);
}
/* Clean up the lb workers data */
- if (lb_limit) {
+ if (lb_limit && worker_size) {
memset(ap_scoreboard_image->balancers, 0,
- sizeof(lb_score) * lb_limit);
+ worker_size * lb_limit);
}
return OK;
}
AP_DECLARE(lb_score *) ap_get_scoreboard_lb(int lb_num)
{
- if (((lb_num < 0) || (lb_limit < lb_num))) {
+ char *ptr;
+ if (((lb_num < 0) || (lb_limit < lb_num)) || (worker_size==0)) {
return(NULL); /* Out of range */
}
- return &ap_scoreboard_image->balancers[lb_num];
+ ptr = (char *) ap_scoreboard_image->balancers + lb_num*worker_size;
+ return (lb_score *) ptr;
}