rlopez3d has asked for the wisdom of the Perl Monks concerning the following question:

I have three servers for downloading using HTTP. I need to test with a given frequency how fast is each one to conviniently redirect the users and achive an optimal downloading managing among the servers. Thanks in advance.
  • Comment on How to test for the fastest server to download from?

Replies are listed 'Best First'.
Re: HelpNeeded!!! How to test for the fastest server to download from?
by Rex(Wrecks) (Curate) on Dec 20, 2001 at 23:11 UTC
    Fork 3 processes, one for each server. Start timers for each of them, whichever reports the least amount of time lapse is your quickest.

    This will give you an accurate picture of which server is, not only initially fastest, but also maintains bandwidth for your connections.

    pings, traceroute, and tools like that can give you a quick idea if that is all you want, however timing the actual process will give you actual performance. Especially in this case where you are redirecting traffic. Doing a simple HTTP get on a known file size and timing the transaction from start to finish should accomplish what you need.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
      Thanks, I think I will do your way. It is exactly what I need.
Re: HelpNeeded!!! How to test for the fastest server to download from?
by Juerd (Abbot) on Dec 20, 2001 at 21:55 UTC
    s/Needed/Wanted/.

    Try using a Stopwatch to time an LWP::Simple::get()

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

      You probably want to use HEAD, not GET. Something like:
      $ua = LWP::UserAgent->new; $request = HTTP::Request->new(HEAD => "$url"); $response = $ua->request($request); $status_line = $response->status_line;
      Using 'GET' on a large page will not really be a good determining factor of response time, but using HEAD will.
Re: HelpNeeded!!! How to test for the fastest server to download from?
by zenmaster (Beadle) on Dec 20, 2001 at 21:58 UTC
    If you want to test the net link (the syntax will differ on Windoze) :
    my @a=`ping -s 1024 $servertotest -c 10`;
    Then some parsing (wonderful regexes) could give you the round trip time and packet loss
    which could be a good way to test connectivity between your script and the 3 servers...

    Now you'll probably have to get the servers load too, to make the best choice.

    UPDATE :

    Here is the parsing code for my box (it's "ping output dependant" ;-)
    $a[$#a-1]=~/.*?(\d+)%.*/; # Get the Packet loss near the % my $pl=$1; my $rtt=(split'/',(split'=',$a[$#a])[1])[1]; # get the average Round +trip time