Author: mturk
Date: Wed Mar 15 23:53:27 2006
New Revision: 386279

URL: http://svn.apache.org/viewcvs?rev=386279&view=rev
Log:
Commit #36138. It was waiting for a long time...
Modified from original patch provided by Chris Lamprecht.

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c
    tomcat/connectors/trunk/jk/native/common/jk_lb_worker.h
    tomcat/connectors/trunk/jk/native/common/jk_status.c
    tomcat/connectors/trunk/jk/native/common/jk_util.c
    tomcat/connectors/trunk/jk/xdocs/changelog.xml

Modified: tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c
URL: 
http://svn.apache.org/viewcvs/tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c?rev=386279&r1=386278&r2=386279&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c Wed Mar 15 23:53:27 
2006
@@ -359,6 +359,77 @@
     return candidate;
 }
 
+static worker_record_t *find_best_bybusyness(lb_worker_t *p,
+                                             jk_logger_t *l)
+{
+    static unsigned int next_offset = 0;
+    unsigned int i;
+    unsigned int j;
+    unsigned int offset;
+    int bfn = 1;  /* Numerator of best busy factor */
+    int bfd = 1;  /* Denominator of best busy factor */
+    int curn; /* Numerator of current busy factor */
+    int curd; /* Denominator of current busy factor */
+
+    int left; /* left and right are used to compare rational numbers */
+    int right;
+
+    /* find the least busy worker */
+    worker_record_t *candidate = NULL;
+
+    offset = next_offset;
+
+    /* First try to see if we have available candidate
+        */
+    for (j = 0; j < p->num_of_workers; j++) {
+        i = (j + offset) % p->num_of_workers;
+
+        /* If the worker is in error state run
+         * retry on that worker. It will be marked as
+         * operational if the retry timeout is elapsed.
+         * The worker might still be unusable, but we try
+         * anyway.
+         */
+        if (JK_WORKER_IN_ERROR(p->lb_workers[i].s)) {
+            retry_worker(&p->lb_workers[i], p->s->recover_wait_time, l);
+        }
+        /* Take into calculation only the workers that are
+         * not in error state, stopped or not disabled.
+         */
+        if (JK_WORKER_USABLE(p->lb_workers[i].s)) {
+            curn = p->lb_workers[i].s->busy;
+            curd = p->lb_workers[i].s->lb_factor;
+
+            /* If the server is restarted under load there is a bug that causes
+             * busy to be reset to zero before all the outstanding connections
+             * finish, they then finally finish.  As a result, the busy value
+             * becomes negative, messing up the busyness load balancing.
+             * When this bug is fixed, this section can be removed
+             */
+            if (curn < 0) {
+               jk_log(l, JK_LOG_WARNING,
+                   "busy value is %d for worker %s, resetting it to zero",
+                   curn, p->lb_workers[i].s->name);
+                p->lb_workers[i].s->busy = 0;
+                curn = 0;
+            }
+
+            /* compare rational numbers: (a/b) < (c/d) iff a*d < c*b
+                        */
+            left  = curn * bfd;
+            right = bfn * curd;
+
+            if (!candidate || (left < right)) {
+                candidate = &p->lb_workers[i];
+                bfn = curn;
+                bfd = curd;
+                next_offset = i + 1;
+            }
+        }
+    }
+    return candidate;
+}
+
 static worker_record_t *find_bysession_route(lb_worker_t *p,
                                              const char *name,
                                              jk_logger_t *l)
@@ -441,6 +512,8 @@
         rc = find_best_byrequests(p, l);
     else if (p->lbmethod == JK_LB_BYTRAFFIC)
         rc = find_best_bytraffic(p, l);
+    else if (p->lbmethod == JK_LB_BYBUSYNESS)
+        rc = find_best_bybusyness(p, l);
     /* By default use worker name as session route */
     if (rc)
         rc->r = &(rc->s->name[0]);

Modified: tomcat/connectors/trunk/jk/native/common/jk_lb_worker.h
URL: 
http://svn.apache.org/viewcvs/tomcat/connectors/trunk/jk/native/common/jk_lb_worker.h?rev=386279&r1=386278&r2=386279&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_lb_worker.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_lb_worker.h Wed Mar 15 23:53:27 
2006
@@ -39,8 +39,10 @@
 
 #define JK_LB_BYREQUESTS      (0)
 #define JK_LB_BYTRAFFIC       (1)
+#define JK_LB_BYBUSYNESS      (2)
 #define JK_LB_METHOD_REQUESTS ("Request")
 #define JK_LB_METHOD_TRAFFIC  ("Traffic")
+#define JK_LB_METHOD_BUSYNESS ("Busyness")
 #define JK_LB_LOCK_DEFAULT     (0)
 #define JK_LB_LOCK_PESSIMISTIC (1)
 #define JK_LB_LM_DEFAULT       ("Optimistic")
@@ -69,7 +71,7 @@
     jk_pool_atom_t buf[TINY_POOL_SIZE];
 
     jk_worker_t worker;
-    JK_CRIT_SEC cs; 
+    JK_CRIT_SEC cs;
 
     /* Shared memory worker data */
     jk_shm_worker_t  *s;

Modified: tomcat/connectors/trunk/jk/native/common/jk_status.c
URL: 
http://svn.apache.org/viewcvs/tomcat/connectors/trunk/jk/native/common/jk_status.c?rev=386279&r1=386278&r2=386279&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_status.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_status.c Wed Mar 15 23:53:27 
2006
@@ -90,6 +90,14 @@
     NULL
 };
 
+static const char *lb_method_type[] = {
+    JK_LB_METHOD_REQUESTS,
+    JK_LB_METHOD_TRAFFIC,
+    JK_LB_METHOD_BUSYNESS,
+    "unknown",
+    NULL
+};
+
 #define HEADERS_NO_CACHE "no-cache", "no-cache", NULL
 
 static const char *headers_vhtml[] = {
@@ -443,7 +451,7 @@
             jk_putv(s, "<td>", status_val_bool(lb->s->sticky_session_force),
                     "</td>", NULL);
             jk_printf(s, "<td>%d</td>", lb->s->retries);
-            jk_printf(s, "<td>%s</td>", lb->lbmethod == JK_LB_BYREQUESTS ? 
JK_LB_METHOD_REQUESTS : JK_LB_METHOD_TRAFFIC);
+            jk_printf(s, "<td>%s</td>", lb_method_type[lb->lbmethod]);
             jk_printf(s, "<td>%s</td>", lb->lblock == JK_LB_LOCK_DEFAULT ? 
JK_LB_LM_DEFAULT : JK_LB_LM_PESSIMISTIC);
             jk_puts(s, "</tr>\n</table>\n<br/>\n");
             jk_puts(s, "<table><tr>"

Modified: tomcat/connectors/trunk/jk/native/common/jk_util.c
URL: 
http://svn.apache.org/viewcvs/tomcat/connectors/trunk/jk/native/common/jk_util.c?rev=386279&r1=386278&r2=386279&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_util.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_util.c Wed Mar 15 23:53:27 2006
@@ -770,6 +770,8 @@
         return JK_LB_BYTRAFFIC;
     else if  (*v == 'r' || *v == 'R' || *v == '0')
         return JK_LB_BYREQUESTS;
+    else if  (*v == 'b' || *v == 'B' || *v == '2')
+        return JK_LB_BYBUSYNESS;
     else
         return JK_LB_BYREQUESTS;
 }

Modified: tomcat/connectors/trunk/jk/xdocs/changelog.xml
URL: 
http://svn.apache.org/viewcvs/tomcat/connectors/trunk/jk/xdocs/changelog.xml?rev=386279&r1=386278&r2=386279&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/xdocs/changelog.xml (original)
+++ tomcat/connectors/trunk/jk/xdocs/changelog.xml Wed Mar 15 23:53:27 2006
@@ -25,6 +25,10 @@
   <br />
   <subsection name="Native">
     <changelog>
+      <update>
+      <bug>36138</bug>: Added Busyness lb method. Patch provided
+      by  Chris Lamprecht. (mturk)
+      </update>
       <fix>
       Fix pessimistic locking mode. The patch correctly handles the
       burst load, by syncing the access to the shared memory data. (mturk)



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to