Load Balancing

I l @ ve RuBoard

Round- Robin DNS

One popular choice for load balancing is round-robin DNS. In a round-robin competition, each player has a match against every other competitor. Similarly, with this method of load balancing, you set up your DNS server to deliver more than one possible IP address for the same domain name . Each time a DNS server is queried, it hands out the next IP on the list and then cycles back again to the first entry. Because a local machine asks for the address only once, it goes back to the same machine on each subsequent request.

Round-robin DNS has the advantage that it's cheap and easy to set up. The problem with it, however, is that it doesn't deal well with situations in which one server is getting overloaded or dies. Normally, this isn't an issue because if requests are being distributed in a roughly even fashion, the load should be about even, too.

Another big problem with round-robin DNS is that if you need to remove a server from the pool, it can take 20 minutes to 24 hours for the change to occur, depending on the Time To Live value of your DNS statement of authority record.

Smart Switches

The next step up the ladder when trying to balance a load is to use a smart switch in front of a number of servers. The quintessential example is a Cisco LocalDirector.

A smart switch can direct traffic using heuristics designed to truly load-balance, making sure that all your servers receive an equal load. In addition, the switch can hide the internal IP addresses of your servers, making it appear that all the traffic is going to one single machine. This makes it easier to change your internal network topology as you need to.

A smart switch can also automatically drop a dead machine out of the pool, minimizing downtime.

The Quick-and-Dirty Solution

To avoid the problem of DNS propagation delays that was mentioned in the section on round-robin DNS, you can use a script that does explicit redirection instead.

You can do a quick-and-dirty redirector that allows you to add or drop servers instantly with a single file edit. Listing 18.1 shows what it looks like.

Listing 18.1 RandomRedirect.jsp
 <% int numSites = 5; int thisTime = (new java.util.Random()).nextInt(numSites); String[] Sites = {"www.newsoftheweird.com", "www.dilbert.com",                 "www.userfriendly.org", "www.luckedcompany.com",                 "www.boston.com/globe/living/comics"} ; response.sendRedirect("http://" + Sites[thisTime]); %> 

In this example, you redirect randomly to one of five Web sites. Now imagine that instead of those five sites, it was www1.bfg.com , www2.bfg.com , and so on. And, instead of being called RandomRedirect.jsp, it was called index.jsp and was located in the root HTML directory of www.bfg.com . What would happen when someone asked for www.bfg.com ?

That's right, the user would be randomly redirected to one of the five servers ”poor man's load balancing. If a site goes down, you just change the list of sites, and no one gets sent to it.

The downside to this method is that, after the initial page display, all the subsequent pages show up as www1 (or whatever) in the URL status bar. And if someone bookmarks a page, that user will always return to that same server. Still, this method offers an alternative to the expense of smart switches.

Load Balancing and Session Persistence

If you use a method of load balancing that doesn't ensure that all requests for a given session go to the same server, you might run into problems with session persistence. For example, suppose that you have two machines (www1 and www2). A customer comes to the site, and a session object is created for the shopping cart on www1 (the machine that the customer is assigned to by the load-balancing mechanism used). If the customer doesn't continue to use www1 for the remainder of the session, he'll lose the state of the shopping cart.

Luckily, all of these methods listed don't have a problem with this pitfall. Round-robin DNS makes the selection of an IP address only once for a given client, so the client consistently uses the same IP until the machine reboots or the DNS expires . Most smart switches can direct all requests from the same client to the same server. And if you explicitly redirect to a server, it will always go to the same machine, by design.

I l @ ve RuBoard


MySQL and JSP Web Applications. Data-Driven Programming Using Tomcat and MySQL
MySQL and JSP Web Applications: Data-Driven Programming Using Tomcat and MySQL
ISBN: 0672323095
EAN: 2147483647
Year: 2002
Pages: 203
Authors: James Turner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net