Load balancing using Mod_Rewrite and perl

In computer networking, load balancing is a technique to spread work between two or more computers, network links, CPUs, hard drives, or other to improve the performance.Here is the way to implement load balancing using mod_rewrite.
Proxy Throughput Round-Robin
suppose we want load balancing between 5 different Servers.In this variant we use mod_rewrite and its proxy throughput feature. First we dedicate www0.z-techsoftware.com to be actually www.z-techsoftware.com by using a single entry in DNS.

www    IN  CNAME   www0.foo.com.
Now make this server as proxy server which will redirect requests to all other servers.we first establish a ruleset which contacts a load balancing script lb.pl for all URLs using .htaccess file.

RewriteEngine on
RewriteMap lb prg:/path/to/lb.pl
RewriteRule ^/(.+)$ ${lb:$1} [P,L]

Then we write lb.pl:

#!/path/to/perl
##
## lb.pl -- load balancing script
##

$| = 1;

$name = "www"; # the hostname base
$first = 1; # the first server (not 0 here, because 0 is myself)
$last = 5; # the last server in the round-robin
$domain = "foo.dom"; # the domainname

$cnt = 0;
while () {
$cnt = (($cnt+1) % ($last+1-$first));
$server = sprintf("%s%d.%s", $name, $cnt+$first, $domain);
print "http://$server/$_";
}

##EOF##


That's it.you are done.Now this server will act as proxy server and pass all requests to other servers one by one.