Author: jfrederic.clere(a)jboss.com
Date: 2008-10-06 16:52:20 -0400 (Mon, 06 Oct 2008)
New Revision: 1937
Modified:
trunk/mod_cluster/native/include/node.h
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Use a different algorithm.
Modified: trunk/mod_cluster/native/include/node.h
===================================================================
--- trunk/mod_cluster/native/include/node.h 2008-10-06 18:40:04 UTC (rev 1936)
+++ trunk/mod_cluster/native/include/node.h 2008-10-06 20:52:20 UTC (rev 1937)
@@ -67,6 +67,8 @@
/* part updated in httpd */
int id; /* id in table and worker id */
+ apr_time_t updatetimelb; /* time of last update of the lbstatus value */
+ int oldelected; /* value of s->elected when calculating the lbstatus */
};
typedef struct nodemess nodemess_t;
@@ -77,9 +79,9 @@
/* config from jboss/tomcat */
nodemess_t mess;
/* filled by httpd */
- apr_time_t updatetime; /* time of last received message */
- int offset; /* offset to the proxy_worker_stat structure */
- char stat[SIZEOFSCORE]; /* to store the status */
+ apr_time_t updatetime; /* time of last received message */
+ int offset; /* offset to the proxy_worker_stat structure */
+ char stat[SIZEOFSCORE]; /* to store the status */
};
typedef struct nodeinfo nodeinfo_t;
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-10-06 18:40:04 UTC
(rev 1936)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-10-06 20:52:20 UTC
(rev 1937)
@@ -65,8 +65,7 @@
#define WAITFORREMOVE 10 /* seconds */
-#define FORGETFACTOR 10 /* Stop changing node lbstatus when too small or too big */
-
+#define TIMEINTERVAL apr_time_from_sec(1) /* recalcul the lbstatus based on number of
request in the time interval */
/*
* Create/Get the worker before using it
*/
@@ -362,6 +361,48 @@
"update_workers_node done");
}
+/*
+ * update the lbfactor of each node if needed,
+ */
+static void update_workers_lbstatus(proxy_server_conf *conf, apr_pool_t *pool, server_rec
*server)
+{
+ int *id, size, i;
+ apr_time_t now;
+ int notok = 0;
+
+ now = apr_time_now();
+
+ /* read the ident of the nodes */
+ id = apr_pcalloc(pool, sizeof(int) * node_storage->get_max_size_node());
+ size = node_storage->get_ids_used_node(id);
+
+ /* XXX: How to skip the balancer that aren't controled by mod_manager */
+
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
+ "update_workers_lbstatus starting");
+
+ /* update lbstatus if needed */
+ for (i=0; i<size; i++) {
+ nodeinfo_t *ou;
+ node_storage->read_node(id[i], &ou);
+ if (ou->mess.updatetimelb < (now - TIMEINTERVAL)) {
+ /* The lbstatus needs to be updated */
+ int elected, oldelected;
+ proxy_worker_stat *stat;
+ char *ptr = (char *) ou;
+ ptr = ptr + ou->offset;
+ stat = (proxy_worker_stat *) ptr;
+ elected = stat->elected;
+ oldelected = ou->mess.oldelected;
+ ou->mess.updatetimelb = now;
+ ou->mess.oldelected = elected;
+ stat->lbstatus = ((elected - oldelected) * 1000) / stat->lbfactor;
+ }
+ }
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
+ "update_workers_lbstatus done");
+}
+
/* reslist constructor */
/* XXX: Should use the proxy_util one. */
static apr_status_t connection_constructor(void **resource, void *params,
@@ -718,7 +759,6 @@
request_rec *r)
{
int i;
- int total_factor = 0;
proxy_worker *worker;
proxy_worker *mycandidate = NULL;
int checking_standby = 0;
@@ -773,12 +813,9 @@
mycandidate = worker;
break; /* Done */
} else {
- if (worker->s->lbstatus < FORGETFACTOR *
worker->s->lbfactor)
- worker->s->lbstatus += worker->s->lbfactor;
- total_factor += worker->s->lbfactor;
if (!mycandidate
|| worker->s->busy < mycandidate->s->busy
- || (worker->s->busy == mycandidate->s->busy
&& worker->s->lbstatus > mycandidate->s->lbstatus)) {
+ || (worker->s->busy == mycandidate->s->busy
&& worker->s->lbstatus < mycandidate->s->lbstatus)) {
mycandidate = worker;
}
}
@@ -791,10 +828,6 @@
}
if (mycandidate) {
- if ((mycandidate->s->lbstatus-total_factor) > - FORGETFACTOR *
mycandidate->s->lbfactor)
- mycandidate->s->lbstatus -= total_factor;
- else
- mycandidate->s->lbstatus = - FORGETFACTOR *
mycandidate->s->lbfactor;
mycandidate->s->elected++;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"proxy: byrequests balancer DONE (%s)",
mycandidate->name);
@@ -1106,6 +1139,8 @@
update_workers_node(conf, pool, s);
/* cleanup removed node in shared memory */
remove_removed_node(pool);
+ /* Calculate the lbstatus for each node */
+ update_workers_lbstatus(conf, pool, s);
apr_pool_destroy(pool);
}
apr_thread_exit(thd, 0);
@@ -1468,34 +1503,7 @@
return DECLINED;
}
if (runtime) {
- int i, total_factor = 0;
- proxy_worker *workers;
- /* We have a sticky load balancer
- * Update the workers status
- * so that even session routes get
- * into account.
- */
- workers = (proxy_worker *)(*balancer)->workers->elts;
- for (i = 0; i < (*balancer)->workers->nelts; i++) {
- /* Take into calculation only the workers that are
- * not in error state or not disabled.
- *
- * TODO: Abstract the below, since this is dependent
- * on the LB implementation
- */
- if (PROXY_WORKER_IS_USABLE(workers)) {
- if (workers->s->lbstatus < FORGETFACTOR *
workers->s->lbfactor)
- workers->s->lbstatus += workers->s->lbfactor;
- total_factor += workers->s->lbfactor;
- }
- workers++;
- }
- if (runtime->s->lbstatus-total_factor > - FORGETFACTOR *
runtime->s->lbfactor)
- runtime->s->lbstatus -= total_factor;
- else
- runtime->s->lbstatus = - FORGETFACTOR * runtime->s->lbfactor;
runtime->s->elected++;
-
*worker = runtime;
}
else if (route && (*balancer)->sticky_force) {