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">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="generator" content="Movable Type 5.2.3" />
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" />
12 <title>Status for Andrew DeFaria: Load Balancing Redirection</title>
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" />
22 <script type="text/javascript" src="http://defaria.com/blogs/Status/mt-site.js"></script>
24 <body class="layout-one-column" onload="individualArchivesOnLoad(commenter_name)">
26 <div id="container-inner" class="pkg">
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>
36 <div id="pagebody-inner" class="pkg">
38 <div id="alpha-inner" class="pkg">
40 <p class="content-nav">
41 <a href="http://defaria.com/blogs/Status/archives/000574.html">« 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 »</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">
52 <li>Implemented a load balancing redirection scheme for cqweb</li>
55 <div id="more" class="entry-more">
56 <h2>Load Balancing CQ Web Servers based on Number of CQ Web Users</h2>
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>
60 <h3>Determining Load</h3>
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>
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>
66 <h2>Algorithm for selecting a server</h2>
68 <p>The algorithm for selecting a non busy server is described as:</p>
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:
72 <table cellspacing=0 cellpadding=2 border=1>
77 <th>ExtendedStatus</th>
102 <p>In such a case we wish to pick server3 since it has no current CQ web users.
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>
106 <p><b>Note:</b> If $random then a server is simply randomly chosen.</p>
108 <p>Unfortunately, given this algorithm, if we had the following situation:</p>
110 <table cellspacing=0 cellpadding=2 border=1>
115 <th>ExtendedStatus</th>
140 <p>Then this algorithm will always return server4.</p>
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>
144 <h3>Random Redirection</h3>
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).
148 <h3>Defining the Server Pool</h3>
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>
152 <h3>Mapping Redirection</h3>
154 <p>In the past users went to http://cqweb/<area>. 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>
156 <p>Instead one must specify the <tt>group</tt> parameter to the redirector script. The script then maintains a map between <areas> -> 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 <area> files anyway. The new form of redirecting <area> file is:
158 <div class=code><pre>
161 <mdeta http-equiv="refresh" content="0; url=http://cqweb.itg.ti.com/cgi-bin/redirect.pl?group=<<i>area</i>>>
165 <h3>Redirect Map</h3>
167 <p>The redirect map, stored in redirect.map, is a file of key/value pairs. For example:</p>
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
187 <h3>Parameters for redirect.pl</h3>
189 <p>The following parameters, specified in the URL, are supported by redirect.pl:</p>
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>
196 <dd>If set then load balancing is attempted based on ExtendedStatus and CQ Web Users as described above. Default: undefined (off)</dd>
199 <dd>If specified the user is not redirected rather debugging information is output.</dd>
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>