Load Balancing is a mechanism for distributing load among AR Servers. These AR Servers are generally node servers because they run the workflow and the load is usually high on them. Load Balancer server is a different physical or logical machine installed on the same environment. In our environment, there is a Perl script run by crontab on each server and it opens or closes port 7070 according to the availability of the server. Then the load balancer server checks port 7070 on a particular server and redirects requests if the port 7070 is open. Otherwise it means the server is not available and no requests are redirected to that server. Here is the code for opening and closing the port:
open (LOG,">>$LOGFILE");
print LOG "\n\n##### Started: " . scalar localtime(). " #####\n";
my $sock;
my $client;
my $flag=0, $debug=0;
while(1) {
open (LOG,">>$LOGFILE");
print LOG "##### Check: " . scalar localtime(). " #####\n";
print "##### Check: " . scalar localtime(). " #####\n";
close(LOG);
$ARScrtl = ars_Login($ARSserver, $ARSuser, $ARSpassword);
if ( ! $ARScrtl)
{
######### Login fails ########
open (LOG,">>$LOGFILE");
print LOG "##### " . scalar localtime(). " Login failed: $ars_errstr #####\n";
#print "##### " . scalar localtime(). " Login failed: $ars_errstr #####\n";
close(LOG);
close($client);
close($sock);
#end of cycle, wait for 10 sec. for next check cycle
sleep(10);
}
else {
######## Login succeeds #######
open (LOG,">>$LOGFILE");
print LOG "##### " . scalar localtime(). " Login successful. #####\n";
#print "##### " . scalar localtime(). " Login successful. #####\n";
close(LOG);
ars_Logoff($ARScrtl);
$sock = new IO::Socket::INET (
LocalHost => $LBChkServer,
LocalPort => $LBChkPort,
Proto => 'tcp',
Listen => 1,
Reuse => 1,
#Blocking => 0
Timeout => 10
);
close($client);
if ( $client =$sock->accept() ) {
#print LOG "New connection!\n";
#sleep(3);
}
close($sock);
}
if($debug eq 1) {
if($flag eq 0) {
$flag = 1;
}
else {
$flag = 0;
}
}
#sleep(1);
}
close($sock);
close(LOG);
No comments:
Post a Comment