TEXT   25

lbset.patch

Guest on 6th August 2021 04:46:53 PM

  1. Index: docs/manual/mod/mod_proxy.xml
  2. ===================================================================
  3. --- docs/manual/mod/mod_proxy.xml       (revision 440792)
  4. +++ docs/manual/mod/mod_proxy.xml       (working copy)
  5. @@ -578,6 +578,12 @@
  6.      generally 120ms), and thus prevent the firewall to drop the connection.
  7.      To enable keepalive set this property value to <code>On</code>.
  8.      </td></tr>
  9. +    <tr><td>lbset</td>
  10. +        <td>0</td>
  11. +        <td>Sets the load balancer cluster set that the worker is a member
  12. +         of. The load balancer will try all members of a lower numbered
  13. +         lbset before trying higher numbered ones.
  14. +    </td></tr>
  15.      <tr><td>loadfactor</td>
  16.          <td>1</td>
  17.          <td>Worker load factor. Used with BalancerMember.
  18. @@ -608,7 +614,7 @@
  19.      <tr><td>status</td>
  20.          <td>-</td>
  21.          <td>Single letter value defining the initial status of
  22. -        this worker: 'D' is disabled, 'S' is stopped
  23. +        this worker: 'D' is disabled, 'S' is stopped, 'H' is hot-standby
  24.          and 'E' is in an error state. Status can be set (which is the default)
  25.          by prepending with '+' or cleared by prepending with '-'.
  26.          Thus, a setting of 'S-E' sets this worker to Stopped and
  27. @@ -685,6 +691,22 @@
  28.        </indent>
  29.        &lt;/Proxy&gt;
  30.      </example>
  31. +
  32. +    <p>Setting up a hot-standby, that will only be used if no other
  33. +     members are available</p>
  34. +    <example>
  35. +      ProxyPass / balancer://hotcluster/ <br />
  36. +      &lt;Proxy balancer://hotcluster&gt;<br />
  37. +      <indent>
  38. +        BalancerMember http://1.2.3.4:8009 loadfactor=1<br />
  39. +        BalancerMember http://1.2.3.5:8009 loadfactor=2<br />
  40. +        # The below is the hot standby<br />
  41. +        BalancerMember http://1.2.3.6:8009 status=+H<br />
  42. +        ProxySet lbmethod=bytraffic
  43. +      </indent>
  44. +      &lt;/Proxy&gt;
  45. +    </example>
  46. +
  47.      
  48.      <p>When used inside a <directive type="section" module="core"
  49.      >Location</directive> section, the first argument is omitted and the local
  50. Index: CHANGES
  51. ===================================================================
  52. --- CHANGES     (revision 440792)
  53. +++ CHANGES     (working copy)
  54. @@ -1,6 +1,10 @@
  55.                                                          -*- coding: utf-8 -*-
  56.  Changes with Apache 2.2.4
  57.  
  58. +  *) mod_proxy_balancer: Workers can now be defined as part of
  59. +     a balancer cluster "set" in which members of a lower-numbered set
  60. +     are preferred over higher numbered ones. [Jim Jagielski]
  61. +
  62.    *) mod_proxy_balancer: Workers can now be defined as "hot standby" which
  63.       will only be used if all other workers are unusable (eg: in
  64.       error or disabled). Also, the balancer-manager displays the election
  65. Index: modules/proxy/mod_proxy_balancer.c
  66. ===================================================================
  67. --- modules/proxy/mod_proxy_balancer.c  (revision 440792)
  68. +++ modules/proxy/mod_proxy_balancer.c  (working copy)
  69. @@ -93,6 +93,7 @@
  70.          /* Set to the original configuration */
  71.          workers[i].s->lbstatus = workers[i].s->lbfactor =
  72.            (workers[i].lbfactor ? workers[i].lbfactor : 1);
  73. +        workers[i].s->lbset = workers[i].lbset;
  74.      }
  75.      /* Set default number of attempts to the number of
  76.       * workers.
  77. @@ -172,10 +173,12 @@
  78.                                         const char *route, request_rec *r)
  79.  {
  80.      int i;
  81. -    int checking_standby = 0;
  82. -    int checked_standby = 0;
  83. +    int checking_standby;
  84. +    int checked_standby;
  85.      
  86.      proxy_worker *worker;
  87. +
  88. +    checking_standby = checked_standby = 0;
  89.      while (!checked_standby) {
  90.          worker = (proxy_worker *)balancer->workers->elts;
  91.          for (i = 0; i < balancer->workers->nelts; i++, worker++) {
  92. @@ -601,6 +604,12 @@
  93.              else if (!strcasecmp(val, "Enable"))
  94.                  wsel->s->status &= ~PROXY_WORKER_DISABLED;
  95.          }
  96. +        if ((val = apr_table_get(params, "ls"))) {
  97. +            int ival = atoi(val);
  98. +            if (ival >= 0 && ival <= 99) {
  99. +                wsel->s->lbset = ival;
  100. +             }
  101. +        }
  102.  
  103.      }
  104.      if (apr_table_get(params, "xml")) {
  105. @@ -663,13 +672,13 @@
  106.              ap_rputs("\n\n<table border=\"0\" style=\"text-align: left;\"><tr>"
  107.                  "<th>Worker URL</th>"
  108.                  "<th>Route</th><th>RouteRedir</th>"
  109. -                "<th>Factor</th><th>Status</th>"
  110. +                "<th>Factor</th><th>Set</th><th>Status</th>"
  111.                  "<th>Elected</th><th>To</th><th>From</th>"
  112.                  "</tr>\n", r);
  113.  
  114.              worker = (proxy_worker *)balancer->workers->elts;
  115.              for (n = 0; n < balancer->workers->nelts; n++) {
  116. -
  117. +                char fbuf[50];
  118.                  ap_rvputs(r, "<tr>\n<td><a href=\"", r->uri, "?b=",
  119.                            balancer->name + sizeof("balancer://") - 1, "&w=",
  120.                            ap_escape_uri(r->pool, worker->name),
  121. @@ -677,7 +686,8 @@
  122.                  ap_rvputs(r, worker->name, "</a></td>", NULL);
  123.                  ap_rvputs(r, "<td>", worker->s->route, NULL);
  124.                  ap_rvputs(r, "</td><td>", worker->s->redirect, NULL);
  125. -                ap_rprintf(r, "</td><td>%d</td><td>", worker->s->lbfactor);
  126. +                ap_rprintf(r, "</td><td>%d</td>", worker->s->lbfactor);
  127. +                ap_rprintf(r, "<td>%d</td><td>", worker->s->lbset);
  128.                  if (worker->s->status & PROXY_WORKER_DISABLED)
  129.                     ap_rputs("Dis ", r);
  130.                  if (worker->s->status & PROXY_WORKER_IN_ERROR)
  131. @@ -691,10 +701,11 @@
  132.                  if (!PROXY_WORKER_IS_INITIALIZED(worker))
  133.                      ap_rputs("-", r);
  134.                  ap_rputs("</td>", r);
  135. -                ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td>", worker->s->elected);
  136. -                ap_rprintf(r, "<td>%" APR_OFF_T_FMT "</td>", worker->s->transferred);
  137. -                ap_rprintf(r, "<td>%" APR_OFF_T_FMT "</td>", worker->s->read);
  138. -                ap_rputs("</tr>\n", r);
  139. +                ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td><td>", worker->s->elected);
  140. +                ap_rputs(apr_strfsize(worker->s->transferred, fbuf), r);
  141. +                ap_rputs("</td><td>", r);
  142. +                ap_rputs(apr_strfsize(worker->s->read, fbuf), r);
  143. +                ap_rputs("</td></tr>\n", r);
  144.  
  145.                  ++worker;
  146.              }
  147. @@ -708,20 +719,22 @@
  148.              ap_rvputs(r, "<form method=\"GET\" action=\"", NULL);
  149.              ap_rvputs(r, r->uri, "\">\n<dl>", NULL);
  150.              ap_rputs("<table><tr><td>Load factor:</td><td><input name=\"lf\" type=text ", r);
  151. -            ap_rprintf(r, "value=\"%d\"></td><tr>\n", wsel->s->lbfactor);
  152. +            ap_rprintf(r, "value=\"%d\"></td></tr>\n", wsel->s->lbfactor);
  153. +            ap_rputs("<tr><td>LB Set:</td><td><input name=\"ls\" type=text ", r);
  154. +            ap_rprintf(r, "value=\"%d\"></td></tr>\n", wsel->s->lbset);
  155.              ap_rputs("<tr><td>Route:</td><td><input name=\"wr\" type=text ", r);
  156.              ap_rvputs(r, "value=\"", wsel->route, NULL);
  157. -            ap_rputs("\"></td><tr>\n", r);
  158. +            ap_rputs("\"></td></tr>\n", r);
  159.              ap_rputs("<tr><td>Route Redirect:</td><td><input name=\"rr\" type=text ", r);
  160.              ap_rvputs(r, "value=\"", wsel->redirect, NULL);
  161. -            ap_rputs("\"></td><tr>\n", r);
  162. +            ap_rputs("\"></td></tr>\n", r);
  163.              ap_rputs("<tr><td>Status:</td><td>Disabled: <input name=\"dw\" value=\"Disable\" type=radio", r);
  164.              if (wsel->s->status & PROXY_WORKER_DISABLED)
  165.                  ap_rputs(" checked", r);
  166.              ap_rputs("> | Enabled: <input name=\"dw\" value=\"Enable\" type=radio", r);
  167.              if (!(wsel->s->status & PROXY_WORKER_DISABLED))
  168.                  ap_rputs(" checked", r);
  169. -            ap_rputs("></td><tr>\n", r);
  170. +            ap_rputs("></td></tr>\n", r);
  171.              ap_rputs("<tr><td colspan=2><input type=submit value=\"Submit\"></td></tr>\n", r);
  172.              ap_rvputs(r, "</table>\n<input type=hidden name=\"w\" ",  NULL);
  173.              ap_rvputs(r, "value=\"", ap_escape_uri(r->pool, wsel->name), "\">\n", NULL);
  174. @@ -844,39 +857,51 @@
  175.      int total_factor = 0;
  176.      proxy_worker *worker;
  177.      proxy_worker *mycandidate = NULL;
  178. -    int checking_standby = 0;
  179. -    int checked_standby = 0;
  180. +    int cur_lbset = 0;
  181. +    int max_lbset = 0;
  182. +    int checking_standby;
  183. +    int checked_standby;
  184.      
  185.      ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
  186.                   "proxy: Entering byrequests for BALANCER (%s)",
  187.                   balancer->name);
  188.  
  189.      /* First try to see if we have available candidate */
  190. -    while (!mycandidate && !checked_standby) {
  191. -        worker = (proxy_worker *)balancer->workers->elts;
  192. -        for (i = 0; i < balancer->workers->nelts; i++, worker++) {
  193. -            if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker)) )
  194. -                continue;
  195. -            /* If the worker is in error state run
  196. -             * retry on that worker. It will be marked as
  197. -             * operational if the retry timeout is elapsed.
  198. -             * The worker might still be unusable, but we try
  199. -             * anyway.
  200. -             */
  201. -            if (!PROXY_WORKER_IS_USABLE(worker))
  202. -                ap_proxy_retry_worker("BALANCER", worker, r->server);
  203. -            /* Take into calculation only the workers that are
  204. -             * not in error state or not disabled.
  205. -             */
  206. -            if (PROXY_WORKER_IS_USABLE(worker)) {
  207. -                worker->s->lbstatus += worker->s->lbfactor;
  208. -                total_factor += worker->s->lbfactor;
  209. -                if (!mycandidate || worker->s->lbstatus > mycandidate->s->lbstatus)
  210. -                    mycandidate = worker;
  211. +    do {
  212. +        checking_standby = checked_standby = 0;
  213. +        while (!mycandidate && !checked_standby) {
  214. +            worker = (proxy_worker *)balancer->workers->elts;
  215. +            for (i = 0; i < balancer->workers->nelts; i++, worker++) {
  216. +                if (!checking_standby) {    /* first time through */
  217. +                    if (worker->s->lbset > max_lbset)
  218. +                        max_lbset = worker->s->lbset;
  219. +                }
  220. +                if (worker->s->lbset > cur_lbset)
  221. +                    continue;
  222. +                if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker)) )
  223. +                    continue;
  224. +                /* If the worker is in error state run
  225. +                 * retry on that worker. It will be marked as
  226. +                 * operational if the retry timeout is elapsed.
  227. +                 * The worker might still be unusable, but we try
  228. +                 * anyway.
  229. +                 */
  230. +                if (!PROXY_WORKER_IS_USABLE(worker))
  231. +                    ap_proxy_retry_worker("BALANCER", worker, r->server);
  232. +                /* Take into calculation only the workers that are
  233. +                 * not in error state or not disabled.
  234. +                 */
  235. +                if (PROXY_WORKER_IS_USABLE(worker)) {
  236. +                    worker->s->lbstatus += worker->s->lbfactor;
  237. +                    total_factor += worker->s->lbfactor;
  238. +                    if (!mycandidate || worker->s->lbstatus > mycandidate->s->lbstatus)
  239. +                        mycandidate = worker;
  240. +                }
  241.              }
  242. +            checked_standby = checking_standby++;
  243.          }
  244. -        checked_standby = checking_standby++;
  245. -    }
  246. +        cur_lbset++;
  247. +    } while (cur_lbset <= max_lbset && !mycandidate);
  248.  
  249.      if (mycandidate) {
  250.          mycandidate->s->lbstatus -= total_factor;
  251. @@ -910,42 +935,54 @@
  252.      apr_off_t mytraffic = 0;
  253.      apr_off_t curmin = 0;
  254.      proxy_worker *worker;
  255. -    int checking_standby = 0;
  256. -    int checked_standby = 0;
  257.      proxy_worker *mycandidate = NULL;
  258. +    int cur_lbset = 0;
  259. +    int max_lbset = 0;
  260. +    int checking_standby;
  261. +    int checked_standby;
  262.  
  263.      ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
  264.                   "proxy: Entering bytraffic for BALANCER (%s)",
  265.                   balancer->name);
  266.  
  267.      /* First try to see if we have available candidate */
  268. -    while (!mycandidate && !checked_standby) {
  269. -        worker = (proxy_worker *)balancer->workers->elts;
  270. -        for (i = 0; i < balancer->workers->nelts; i++, worker++) {
  271. -            if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker)) )
  272. -                continue;
  273. -            /* If the worker is in error state run
  274. -             * retry on that worker. It will be marked as
  275. -             * operational if the retry timeout is elapsed.
  276. -             * The worker might still be unusable, but we try
  277. -             * anyway.
  278. -             */
  279. -            if (!PROXY_WORKER_IS_USABLE(worker))
  280. -                ap_proxy_retry_worker("BALANCER", worker, r->server);
  281. -            /* Take into calculation only the workers that are
  282. -             * not in error state or not disabled.
  283. -             */
  284. -            if (PROXY_WORKER_IS_USABLE(worker)) {
  285. -                mytraffic = (worker->s->transferred/worker->s->lbfactor) +
  286. -                            (worker->s->read/worker->s->lbfactor);
  287. -                if (!mycandidate || mytraffic < curmin) {
  288. -                    mycandidate = worker;
  289. -                    curmin = mytraffic;
  290. +    do {
  291. +        checking_standby = checked_standby = 0;
  292. +        while (!mycandidate && !checked_standby) {
  293. +            worker = (proxy_worker *)balancer->workers->elts;
  294. +            for (i = 0; i < balancer->workers->nelts; i++, worker++) {
  295. +                if (!checking_standby) {    /* first time through */
  296. +                    if (worker->s->lbset > max_lbset)
  297. +                        max_lbset = worker->s->lbset;
  298.                  }
  299. +                if (worker->s->lbset > cur_lbset)
  300. +                    continue;
  301. +                if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker)) )
  302. +                    continue;
  303. +                /* If the worker is in error state run
  304. +                 * retry on that worker. It will be marked as
  305. +                 * operational if the retry timeout is elapsed.
  306. +                 * The worker might still be unusable, but we try
  307. +                 * anyway.
  308. +                 */
  309. +                if (!PROXY_WORKER_IS_USABLE(worker))
  310. +                    ap_proxy_retry_worker("BALANCER", worker, r->server);
  311. +                /* Take into calculation only the workers that are
  312. +                 * not in error state or not disabled.
  313. +                 */
  314. +                if (PROXY_WORKER_IS_USABLE(worker)) {
  315. +                    mytraffic = (worker->s->transferred/worker->s->lbfactor) +
  316. +                                (worker->s->read/worker->s->lbfactor);
  317. +                    if (!mycandidate || mytraffic < curmin) {
  318. +                        mycandidate = worker;
  319. +                        curmin = mytraffic;
  320. +                    }
  321. +                }
  322.              }
  323. +            checked_standby = checking_standby++;
  324.          }
  325. -        checked_standby = checking_standby++;
  326. -    }
  327. +        cur_lbset++;
  328. +    } while (cur_lbset <= max_lbset && !mycandidate);
  329.  
  330.      if (mycandidate) {
  331.          mycandidate->s->elected++;
  332. Index: modules/proxy/mod_proxy.c
  333. ===================================================================
  334. --- modules/proxy/mod_proxy.c   (revision 440792)
  335. +++ modules/proxy/mod_proxy.c   (working copy)
  336. @@ -244,6 +244,12 @@
  337.          else
  338.              worker->flush_wait = ival * 1000;    /* change to microseconds */
  339.      }
  340. +    else if (!strcasecmp(key, "lbset")) {
  341. +        ival = atoi(val);
  342. +        if (ival < 0 || ival > 99)
  343. +            return "lbset must be between 0 and 99";
  344. +        worker->lbset = ival;
  345. +    }
  346.      else {
  347.          return "unknown Worker parameter";
  348.      }
  349. @@ -1800,7 +1806,7 @@
  350.          ap_rputs("\n\n<table border=\"0\"><tr>"
  351.                   "<th>Sch</th><th>Host</th><th>Stat</th>"
  352.                   "<th>Route</th><th>Redir</th>"
  353. -                 "<th>F</th><th>Acc</th><th>Wr</th><th>Rd</th>"
  354. +                 "<th>F</th><th>Set</th><th>Acc</th><th>Wr</th><th>Rd</th>"
  355.                   "</tr>\n", r);
  356.  
  357.          worker = (proxy_worker *)balancer->workers->elts;
  358. @@ -1819,7 +1825,8 @@
  359.              ap_rvputs(r, "</td><td>", worker->s->route, NULL);
  360.              ap_rvputs(r, "</td><td>", worker->s->redirect, NULL);
  361.              ap_rprintf(r, "</td><td>%d</td>", worker->s->lbfactor);
  362. -            ap_rprintf(r, "<td>%d</td><td>", (int)(worker->s->elected));
  363. +            ap_rprintf(r, "<td>%d</td>", worker->s->lbset);
  364. +            ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td><td>", worker->s->elected);
  365.              ap_rputs(apr_strfsize(worker->s->transferred, fbuf), r);
  366.              ap_rputs("</td><td>", r);
  367.              ap_rputs(apr_strfsize(worker->s->read, fbuf), r);
  368. Index: modules/proxy/mod_proxy.h
  369. ===================================================================
  370. --- modules/proxy/mod_proxy.h   (revision 440792)
  371. +++ modules/proxy/mod_proxy.h   (working copy)
  372. @@ -279,6 +279,8 @@
  373.      char            route[PROXY_WORKER_MAX_ROUTE_SIZ+1];
  374.      char            redirect[PROXY_WORKER_MAX_ROUTE_SIZ+1];
  375.      void            *context;   /* general purpose storage */
  376. +    apr_size_t      busy;       /* busyness factor */
  377. +    int             lbset;      /* load balancer cluster set */
  378.  } proxy_worker_stat;
  379.  
  380.  /* Worker configuration */
  381. @@ -299,29 +301,30 @@
  382.      apr_interval_time_t ttl;    /* maximum amount of time in seconds a connection
  383.                                   * may be available while exceeding the soft limit */
  384.      apr_interval_time_t timeout; /* connection timeout */
  385. -    char                timeout_set;
  386. +    char            timeout_set;
  387.      apr_interval_time_t acquire; /* acquire timeout when the maximum number of connections is exceeded */
  388. -    char                acquire_set;
  389. -    apr_size_t          recv_buffer_size;
  390. -    char                recv_buffer_size_set;
  391. -    apr_size_t          io_buffer_size;
  392. -    char                io_buffer_size_set;
  393. -    char                keepalive;
  394. -    char                keepalive_set;
  395. +    char            acquire_set;
  396. +    apr_size_t      recv_buffer_size;
  397. +    char            recv_buffer_size_set;
  398. +    apr_size_t      io_buffer_size;
  399. +    char            io_buffer_size_set;
  400. +    char            keepalive;
  401. +    char            keepalive_set;
  402.      proxy_conn_pool     *cp;        /* Connection pool to use */
  403.      proxy_worker_stat   *s;         /* Shared data */
  404. -    void                *opaque;    /* per scheme worker data */
  405. -    int                 is_address_reusable;
  406. +    void            *opaque;    /* per scheme worker data */
  407. +    int             is_address_reusable;
  408.  #if APR_HAS_THREADS
  409.      apr_thread_mutex_t  *mutex;  /* Thread lock for updating address cache */
  410.  #endif
  411. -    void                *context;   /* general purpose storage */
  412. +    void            *context;   /* general purpose storage */
  413.      enum {
  414.           flush_off,
  415.           flush_on,
  416.           flush_auto
  417.      } flush_packets;           /* control AJP flushing */
  418. -    int                 flush_wait;  /* poll wait time in microseconds if flush_auto */
  419. +    int             flush_wait;  /* poll wait time in microseconds if flush_auto */
  420. +    int             lbset;      /* load balancer cluster set */
  421.  };
  422.  
  423.  /*

Raw Paste


Login or Register to edit or fork this paste. It's free.