Initial add of defaria.com
[clearscm.git] / defaria.com / blogs / Status / archives / 000575.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
4 <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6    <meta name="generator" content="Movable Type 5.2.3" />
7
8    <link rel="stylesheet" href="http://defaria.com/blogs/Status/styles-site.css" type="text/css" />
9    <link rel="alternate" type="application/atom+xml" title="Atom" href="http://defaria.com/blogs/Status/atom.xml" />
10    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://defaria.com/blogs/Status/index.xml" />
11
12    <title>Status for Andrew DeFaria: Load Balancing Redirection</title>
13
14    <link rel="start" href="http://defaria.com/blogs/Status/" title="Home" />
15    <link rel="prev" href="http://defaria.com/blogs/Status/archives/000574.html" title="JVM Stack/Heap Sizes" />
16    <link rel="next" href="http://defaria.com/blogs/Status/archives/000576.html" title="Redirecting on ErrorDocument" />
17
18    
19
20    
21
22    <script type="text/javascript" src="http://defaria.com/blogs/Status/mt-site.js"></script>
23 </head>
24 <body class="layout-one-column" onload="individualArchivesOnLoad(commenter_name)">
25    <div id="container">
26       <div id="container-inner" class="pkg">
27
28          <div id="banner">
29             <div id="banner-inner" class="pkg">
30                <h1 id="banner-header"><a href="http://defaria.com/blogs/Status/" accesskey="1">Status for Andrew DeFaria</a></h1>
31                <h2 id="banner-description">Searchable status reports and work log</h2>
32             </div>
33          </div>
34
35          <div id="pagebody">
36             <div id="pagebody-inner" class="pkg">
37                <div id="alpha">
38                   <div id="alpha-inner" class="pkg">
39
40                      <p class="content-nav">
41                         <a href="http://defaria.com/blogs/Status/archives/000574.html">&laquo; JVM Stack/Heap Sizes</a> |
42                         <a href="http://defaria.com/blogs/Status/">Main</a>
43                         | <a href="http://defaria.com/blogs/Status/archives/000576.html">Redirecting on ErrorDocument &raquo;</a>
44                      </p>
45
46                      <a id="a000575"></a>
47                      <div class="entry" id="entry-575">
48                         <h3 class="entry-header">Load Balancing Redirection</h3>
49                         <div class="entry-content">
50                            <div class="entry-body">
51                               <ul>
52   <li>Implemented a load balancing redirection scheme for cqweb</li>
53 </ul>
54                            </div>
55                            <div id="more" class="entry-more">
56                               <h2>Load Balancing CQ Web Servers based on Number of CQ Web Users</h2>
57
58 <p>The task at hand was to write a redirector that load balances amongst a number of CQ Web servers based on the number of CQ Web Users currently on each server. Additionally, based on how the user came into the CQ Web server farm, redirect them to the proper schema.</p>
59
60 <h3>Determining Load</h3>
61
62 <p>The old IIS CQ Web Server used to allow you to query the number of active CQ Web Users. The new Apache/Tomcat server only allows admins to do this. Additionally the admin need to be logged in, thus have a valid token. IBM/Rational suggests using Apache's server-status URL to determine load. However that only displays number of Apache requests in progress not number of CQ Web Users.</p>
63
64 <p>If ExtendedStatus is turned on then Apache lists each connection and the URL they are working on. By filtering "GET /cqweb" we can get a rough estimate of the number of CQ Web Users. There is a problem in that the redirector script cannot query the same web server that it's running on. Additionally this information can only be obtained if ExtendedStatus is turned on.</p>
65
66 <h2>Algorithm for selecting a server</h2>
67
68 <p>The algorithm for selecting a non busy server is described as:</p>
69
70 <p>Pick a lightly loaded server out of the pool. Note that if a server is not running with ExtendedStatus on then $cq_users will be undef. This is different than the case where the server has ExtendedStatus on but there just aren't any CQ Web users (which would be denoted by $cq_users = 0). Thus we may have the condition where:
71
72 <table cellspacing=0 cellpadding=2 border=1>
73   <tbody>
74     <tr>
75       <th>Server</th>
76       <th>cq_users</th>
77       <th>ExtendedStatus</th>
78     </tr>
79     <tr>
80       <td>server1</td>
81       <td>undef</td>
82       <td>off</td>
83     </tr>
84     <tr>
85       <td>server2</td>
86       <td>20</td>
87       <td>on</td>
88     </tr>
89     <tr>
90       <td>server3</td>
91       <td>0</td>
92       <td>on</td>
93     </tr>
94     <tr>
95       <td>server4</td>
96       <td>10</td>
97       <td>on</td>
98     </tr>
99   </tbody>
100 <table>
101
102 <p>In such a case we wish to pick server3 since it has no current CQ web users.
103
104 <p>The algorithm used here will be to remove all servers from the pool who are not running with ExtendedStatus on since we cannot reliably tell how loaded the server is from the standpoint of CQ Web users. If, however, no servers have ExtendedStatus on (thus all $cq_users return as undef) then we will consider the $nbr_apache_requests. IOW $nbr_apache_requests is not equivalent with $cq_users and thus they cannot be compared together. But if no server is running with ExtendedStatus on we need to pick something!</p>
105
106 <p><b>Note:</b> If $random then a server is simply randomly chosen.</p>
107
108 <p>Unfortunately, given this algorithm, if we had the following situation:</p>
109  
110 <table cellspacing=0 cellpadding=2 border=1>
111   <tbody>
112     <tr>
113       <th>Server</th>
114       <th>cq_users</th>
115       <th>ExtendedStatus</th>
116     </tr>
117     <tr>
118       <td>server1</td>
119       <td>undef</td>
120       <td>on</td>
121     </tr>
122     <tr>
123       <td>server2</td>
124       <td>undef</td>
125       <td>off</td>
126     </tr>
127     <tr>
128       <td>server3</td>
129       <td>undef</td>
130       <td>off</td>
131     </tr>
132     <tr>
133       <td>server4</td>
134       <td>10</td>
135       <td>on</td>
136     </tr>
137   </tbody>
138 <table>
139
140 <p>Then this algorithm will always return server4.</p>
141
142 <p><b><font color=red>Important Note:</font></b> The web server doing the redirection cannot be queried. Attempting to do so hangs! Therefore it cannot participate in the server pool. It is recommended that another web server be set up as the redirector and the DNS name cqweb assigned to it. This web server can, however, participate by being a Clearquest Request Manager.</p>
143
144 <h3>Random Redirection</h3>
145
146 <p>The script can also redirect randomly instead of relying on load of CQ Web Users. Currently there are 3 servers in the pool. Only one of them has ExtendedStatus turned on. As such redirecting by load will always resolve to the one server using, the one running with ExtendedStatus on. This is not good. So currently it just picks a server randomly from the pool. This behavior is controlled by the <tt>lb</tt> parameter (currently defaulted to off meaning pick server randomly).
147
148 <h3>Defining the Server Pool</h3>
149
150 <p>The server pool is defined by a small file, servers.cfg, which simply list the servers participating in the pool. Servers can be added or removed dynamically.</p>
151
152 <h3>Mapping Redirection</h3>
153
154 <p>In the past users went to http://cqweb/&lt;area&gt;. These <areas> were HTML files in the DocumentRoot which redirected to a series of redirection scripts. It was hoped that HTTP_REFERER could be used to determine where to redirect the visitor. Unfortunately HTTP_REFERER is not guaranteed and indeed it's undefined on the web servers!</p>
155
156 <p>Instead one must specify the <tt>group</tt> parameter to the redirector script. The script then maintains a map between &lt;areas&gt; -> Schema/ContextIDs. If the group is not specified or not in the map then the user is redirected to the main login page. This is not viewed as a hardship because we need redirecting &lt;area&gt; files anyway. The new form of redirecting &lt;area&gt; file is:
157
158 <div class=code><pre>
159 &lt;html&gt;
160 &lt;head&gt;
161 &ltmdeta http-equiv="refresh" content="0; url=http://cqweb.itg.ti.com/cgi-bin/redirect.pl?group=&lt<i>area</i>&gt;&gt;
162 &lt;/head&gt;
163 </pre></div>
164
165 <h3>Redirect Map</h3>
166
167 <p>The redirect map, stored in redirect.map, is a file of key/value pairs. For example:</p>
168
169 <div class=code><pre>
170 CMDT:           &schema=CMDT.2003.06.00&contextid=CMDT
171 CSSD:           &schema=omap.2002.05.00&contextid=OMAPS
172 DLP-Play:       &schema=DLP.2003.06.00&contextid=Play
173 DLP:            &schema=DLP.2003.06.00&contextid=DLP
174 DMD-p:          &schema=DLP.2003.06.00&contextid=DMD-p
175 DMD:            &schema=DLP.2003.06.00&contextid=DMD
176 GCM:            &schema=CMDT.2003.06.00&contextid=GCM
177 HPALP:          &schema=HPA_MKT_LP&contextid=HPALP
178 LDM:            &schema=CMDT.2003.06.00&contextid=LDM
179 NV:             &schema=CMDT.2003.06.00&contextid=NV
180 SDO:            &schema=SDS.2003.06.00&contextid=SDSCM
181 SDO_TEST:       &schema=SDS_TST_DEV&contextid=SDSCM
182 WiMax:          &schema=WiMax.SR5&contextid=WiMax
183 mDTV:           &schema=mDTV.2003.06.00&contextid=MDTV
184 mDTV_play:      &schema=mDTV.2003.06.00&contextid=PLAY
185 </pre></div>
186
187 <h3>Parameters for redirect.pl</h3>
188
189 <p>The following parameters, specified in the URL, are supported by redirect.pl:</p>
190
191 <dl>
192   <dt>group</dt>
193     <dd>Specifies the key into the redirect.map for the schema/contextid. If not specified then defaults to main login page of the selected server</dd>
194
195   <dt>lb</dt>
196     <dd>If set then load balancing is attempted based on ExtendedStatus and CQ Web Users as described above. Default: undefined (off)</dd>
197
198   <dt>debug</dt>
199     <dd>If specified the user is not redirected rather debugging information is output.</dd>
200 </dl>
201                            </div>
202                         </div>
203                         <p class="entry-footer">
204                            <span class="post-footers">Posted by  on September 29, 2006  2:35 PM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000575.html">Permalink</a>
205                         </p>
206                      </div>
207
208                      
209
210                      
211                   </div>
212                </div>
213             </div>
214          </div>
215       </div>
216    </div>
217 </body>
218 </html>