Building Network Redundancy into a Perl Client

From: Joshua Berry (jberry_at_PENSON.COM)
Date: 12/02/04


Date: Thu, 2 Dec 2004 13:44:10 -0600
To: <beginners@perl.org>

I am trying to implement redundancy in a client application that I am
writing so that I can have a primary server and a backup server. The
client is tailing a logfile and sends results to a server for
processing, at the end of the tail loop it sends data to a function that
tries to establish a connection to the primary server and send the data,
if that fails then the data is sent to the backup (failover) server.
The way the function works, if the primary comes back online then it
automatically knows and starts sending data back to the primary.

The only problem with the way this is implemented is that every
connection remains for a couple of minutes in the TIME_WAIT stage:

tcp 0 0 xxx.xxx.xxx.xxx:xxx xxx.xxx.xxx.xxx:xxx
TIME_WAIT
tcp 0 0 xxx.xxx.xxx.xxx:xxx xxx.xxx.xxx.xxx:xxx
TIME_WAIT

Which adds up if I am sending several connections per minute or possibly
per second. My question is, is there a way to bypass the TIME_WAIT
stage or at least reduce the time it is in this stage from within the
program? Below is the subroutine and how it is called. If there is
another way of doing this please let me know.

sub sendData {
        my $xmlfile = shift;

        my $client = new IO::Socket::SSL (
                PeerAddr => $server,
                PeerPort => $port,
                Proto => 'tcp',
                ReuseAddr => 1
                );
        print DBLOG "Could't create primary socket: $!\n" unless
$client;

        my $backup = new IO::Socket::SSL (
                PeerAddr => $bakserv,
                PeerPort => $bakport,
                Proto => 'tcp',
                ReuseAddr => 1
                ) unless $client;

        if (not defined $client && not defined $backup) {
                print DBLOG "Couln't create secondary socket: $!\n"
unless $backup;
        }

        if (defined $client) {
                print $client $xmlfile;
        } elsif (defined $backup) {
                print $backup $xmlfile unless $client;
        }
}

sendData($sendXml);

Thanks,
Josh Berry | CISSP GCIA
Information Security
214-765-1296
 
--------------------------------------------------------------------
If you spend more on coffee than on IT security, you will be hacked.
What's more, you deserve to be hacked.
     -- (Former) White House Cybersecurity adviser Richard Clarke



Relevant Pages

  • Re: DataExchange - anyone using this product ?
    ... you configure the primary server to periodically ... This sync process sends all ... server and switch to the backup server. ...
    (comp.databases.btrieve)
  • RE: Building Network Redundancy into a Perl Client
    ... > that I am writing so that I can have a primary server and a ... > backup server. ... The client is tailing a logfile and sends ... > every connection remains for a couple of minutes in the ...
    (perl.beginners)
  • Re: DHCP update when DNS unavailable.
    ... > If the primary server does not respond but the zone is ... > replicated through multimaster replication, ... > If the update fails because the server is not available, ... > the client logs a message in the event log, ...
    (microsoft.public.win2000.dns)
  • Re: failover web site
    ... > Hi we have an application where it is important that if the main web site ... > goes down users are redirected to our backup server. ... It's not a server issue -- it's a client issue and HTTP clients don't ... but due mostly to the CLIENT software. ...
    (microsoft.public.windows.server.dns)
  • Re: failover web site
    ... > I was thinking run the DNS for the domain name on both the servers. ... > the 1st name server as the primary server and the 2nd name ... and the backup server has an A record pointing to itself. ... > goes down the client dns will request from the backup dns giving it ...
    (microsoft.public.windows.server.dns)