2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_lbmethod_byrequests.xml.meta">
25 <name>mod_lbmethod_byrequests</name>
26 <description>Request Counting load balancer scheduler algorithm for <module
27 >mod_proxy_balancer</module></description>
28 <status>Extension</status>
29 <sourcefile>mod_lbmethod_byrequests.c</sourcefile>
30 <identifier>lbmethod_byrequests_module</identifier>
31 <compatibility>Split off from <module>mod_proxy_balancer</module> in 2.3</compatibility>
34 <!-- FIXME: --> <p>This document is still under development.</p>
36 <seealso><module>mod_proxy</module></seealso>
37 <seealso><module>mod_proxy_balancer</module></seealso>
39 <section id="requests">
40 <title>Request Counting Algorithm</title>
41 <p>Enabled via <code>lbmethod=byrequests</code>, the idea behind this
42 scheduler is that we distribute the requests among the
43 various workers to ensure that each gets their configured share
44 of the number of requests. It works as follows:</p>
46 <p><dfn>lbfactor</dfn> is <em>how much we expect this worker
47 to work</em>, or <em>the workers's work quota</em>. This is
48 a normalized value representing their "share" of the amount of
51 <p><dfn>lbstatus</dfn> is <em>how urgent this worker has to work
52 to fulfill its quota of work</em>.</p>
54 <p>The <dfn>worker</dfn> is a member of the load balancer,
55 usually a remote host serving one of the supported protocols.</p>
57 <p>We distribute each worker's work quota to the worker, and then look
58 which of them needs to work most urgently (biggest lbstatus). This
59 worker is then selected for work, and its lbstatus reduced by the
60 total work quota we distributed to all workers. Thus the sum of all
61 lbstatus does not change(*) and we distribute the requests
64 <p>If some workers are disabled, the others will
65 still be scheduled correctly.</p>
67 <example><pre><code>for each worker in workers
68 worker lbstatus += worker lbfactor
69 total factor += worker lbfactor
70 if worker lbstatus > candidate lbstatus
73 candidate lbstatus -= total factor</code></pre>
76 <p>If a balancer is configured as follows:</p>
96 <p>And <var>b</var> gets disabled, the following schedule is produced:</p>
104 <tr><th>lbstatus</th>
105 <td><em>-50</em></td>
109 <tr><th>lbstatus</th>
112 <td><em>-25</em></td>
114 <tr><th>lbstatus</th>
118 <td><em>0</em></td></tr>
119 <tr><td colspan="5">(repeat)</td></tr>
122 <p>That is it schedules: <var>a</var> <var>c</var> <var>d</var>
123 <var>a</var> <var>c</var> <var>d</var> <var>a</var> <var>c</var>
124 <var>d</var> ... Please note that:</p>
132 <tr><th>lbfactor</th>
139 <p>Has the exact same behavior as:</p>
147 <tr><th>lbfactor</th>
154 <p>This is because all values of <dfn>lbfactor</dfn> are normalized
155 with respect to the others. For:</p>
162 <tr><th>lbfactor</th>
168 <p>worker <var>b</var> will, on average, get 4 times the requests
169 that <var>a</var> and <var>c</var> will.</p>
171 <p>The following asymmetric configuration works as one would expect:</p>
177 <tr><th>lbfactor</th>
180 <tr><td colspan="2"> </td></tr>
181 <tr><th>lbstatus</th>
182 <td><em>-30</em></td>
184 <tr><th>lbstatus</th>
186 <td><em>-40</em></td></tr>
187 <tr><th>lbstatus</th>
190 <tr><th>lbstatus</th>
191 <td><em>-20</em></td>
193 <tr><th>lbstatus</th>
194 <td><em>-50</em></td>
196 <tr><th>lbstatus</th>
198 <td><em>-20</em></td></tr>
199 <tr><th>lbstatus</th>
200 <td><em>-10</em></td>
202 <tr><th>lbstatus</th>
203 <td><em>-40</em></td>
205 <tr><th>lbstatus</th>
207 <td><em>-30</em></td></tr>
208 <tr><th>lbstatus</th>
211 <tr><td colspan="3">(repeat)</td></tr>
214 <p>That is after 10 schedules, the schedule repeats and 7 <var>a</var>
215 are selected with 3 <var>b</var> interspersed.</p>