httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r686805 - in /httpd/httpd/trunk: docs/manual/mod/mod_proxy.xml docs/manual/mod/mod_proxy_balancer.xml modules/proxy/mod_proxy_balancer.c
Date Mon, 18 Aug 2008 15:59:49 GMT
Author: jim
Date: Mon Aug 18 08:59:48 2008
New Revision: 686805

URL: http://svn.apache.org/viewvc?rev=686805&view=rev
Log:
Add in bybusyness LB method, via Joel Gluth in
   https://issues.apache.org/bugzilla/show_bug.cgi?id=45501

NOTE: Name changed and added in to ease enhancement/bugfixes

Modified:
    httpd/httpd/trunk/docs/manual/mod/mod_proxy.xml
    httpd/httpd/trunk/docs/manual/mod/mod_proxy_balancer.xml
    httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c

Modified: httpd/httpd/trunk/docs/manual/mod/mod_proxy.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_proxy.xml?rev=686805&r1=686804&r2=686805&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_proxy.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_proxy.xml Mon Aug 18 08:59:48 2008
@@ -818,8 +818,9 @@
         <td>byrequests</td>
         <td>Balancer load-balance method. Select the load-balancing scheduler
         method to use. Either <code>byrequests</code>, to perform weighted
-        request counting or <code>bytraffic</code>, to perform weighted
-        traffic byte count balancing. Default is <code>byrequests</code>.
+        request counting, <code>bytraffic</code>, to perform weighted
+        traffic byte count balancing, or <code>bybusyness</code>, to perform

+        pending request balancing. Default is <code>byrequests</code>.
     </td></tr>
     <tr><td>maxattempts</td>
         <td>1</td>

Modified: httpd/httpd/trunk/docs/manual/mod/mod_proxy_balancer.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_proxy_balancer.xml?rev=686805&r1=686804&r2=686805&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_proxy_balancer.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_proxy_balancer.xml Mon Aug 18 08:59:48 2008
@@ -50,11 +50,11 @@
 
 <section id="scheduler">
     <title>Load balancer scheduler algorithm</title>
-    <p>At present, there are 2 load balancer scheduler algorithms available
-    for use: Request Counting and Weighted Traffic Counting. These are controlled
-    via the <code>lbmethod</code> value of the Balancer definition. See
-    the <directive module="mod_proxy">ProxyPass</directive> directive for
-    more information.</p>
+    <p>At present, there are 3 load balancer scheduler algorithms available
+    for use: Request Counting, Weighted Traffic Counting and Pending Request 
+    Counting. These are controlled via the <code>lbmethod</code> value of
+    the Balancer definition. See the <directive module="mod_proxy">ProxyPass</directive>

+    directive for more information.</p>
 
 </section>
 
@@ -287,6 +287,25 @@
 
 </section>
 
+<section id="busyness">
+
+    <title>Pending Request Counting Algorithm</title>
+
+    <p>Enabled via <code>lbmethod=bybusyness</code>, this scheduler keeps
+    track of how many requests each worker is assigned at present. A new
+    request is automatically assigned to the worker with the lowest
+    number of active requests. This is useful in the case of workers
+    that queue incoming requests independently of Apache, to ensure that
+    queue length stays even and a request is always given to the worker
+    most likely to service it fastest.</p>
+
+    <p>In the case of multiple least-busy workers, the statistics (and
+    weightings) used by the Request Counting method are used to break the
+    tie. Over time, the distribution of work will come to resemble that
+    characteristic of <code>byrequests</code>.</p>
+
+</section>
+
 <section id="environment">
     <title>Exported Environment Variables</title>
     <p>At present there are 6 environment variables exported:</p>

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c?rev=686805&r1=686804&r2=686805&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c Mon Aug 18 08:59:48 2008
@@ -367,7 +367,9 @@
         }
 #endif
     }
+
     return candidate;
+
 }
 
 static int rewrite_url(request_rec *r, proxy_worker *worker,
@@ -538,6 +540,8 @@
         *worker = runtime;
     }
 
+    (*worker)->s->busy++;
+
     /* Add balancer/worker info to env. */
     apr_table_setn(r->subprocess_env,
                    "BALANCER_NAME", (*balancer)->name);
@@ -598,7 +602,11 @@
 
 #endif
 
+    if (worker && worker->s->busy)
+        worker->s->busy--;
+
     return OK;
+
 }
 
 static void recalc_factors(proxy_balancer *balancer)
@@ -1111,6 +1119,91 @@
     return mycandidate;
 }
 
+static proxy_worker *find_best_bybusyness(proxy_balancer *balancer,
+                                request_rec *r)
+{
+
+    int i;
+    proxy_worker *worker;
+    proxy_worker *mycandidate = NULL;
+    int cur_lbset = 0;
+    int max_lbset = 0;
+    int checking_standby;
+    int checked_standby;
+
+    int total_factor = 0;
+    
+    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+                 "proxy: Entering bybusyness for BALANCER (%s)",
+                 balancer->name);
+
+    /* First try to see if we have available candidate */
+    do {
+
+        checking_standby = checked_standby = 0;
+        while (!mycandidate && !checked_standby) {
+
+            worker = (proxy_worker *)balancer->workers->elts;
+            for (i = 0; i < balancer->workers->nelts; i++, worker++) {
+                if  (!checking_standby) {    /* first time through */
+                    if (worker->s->lbset > max_lbset)
+                        max_lbset = worker->s->lbset;
+                }
+
+                if (worker->s->lbset > cur_lbset)
+                    continue;
+
+                if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker))
)
+                    continue;
+
+                /* 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 (!PROXY_WORKER_IS_USABLE(worker))
+                    ap_proxy_retry_worker("BALANCER", worker, r->server);
+
+                /* Take into calculation only the workers that are
+                 * not in error state or not disabled.
+                 */
+                if (PROXY_WORKER_IS_USABLE(worker)) {
+
+                    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))
+                        mycandidate = worker;
+
+                }
+
+            }
+
+            checked_standby = checking_standby++;
+
+        }
+
+        cur_lbset++;
+
+    } while (cur_lbset <= max_lbset && !mycandidate);
+
+    if (mycandidate) {
+
+        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+                     "proxy: selected worker \"%s\" by busy factor %i (request lbstatus %i)",
+                     mycandidate->name, mycandidate->s->busy, mycandidate->s->lbstatus);
+
+        mycandidate->s->lbstatus -= total_factor;
+
+    }
+
+    return mycandidate;
+
+}
+
 /*
  * How to add additional lbmethods:
  *   1. Create func which determines "best" candidate worker
@@ -1131,6 +1224,14 @@
     NULL
 };
 
+static const proxy_balancer_method bybusyness =
+{
+    "bybusyness",
+    &find_best_bybusyness,
+    NULL
+};
+
+
 static void ap_proxy_balancer_register_hook(apr_pool_t *p)
 {
     /* Only the mpm_winnt has child init hook handler.
@@ -1147,6 +1248,7 @@
     proxy_hook_canon_handler(proxy_balancer_canon, NULL, NULL, APR_HOOK_FIRST);
     ap_register_provider(p, PROXY_LBMETHOD, "bytraffic", "0", &bytraffic);
     ap_register_provider(p, PROXY_LBMETHOD, "byrequests", "0", &byrequests);
+    ap_register_provider(p, PROXY_LBMETHOD, "bybusyness", "0", &bybusyness);
 }
 
 module AP_MODULE_DECLARE_DATA proxy_balancer_module = {



Mime
View raw message