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

Hello Monks,

I'm working on a script that basically just goes and a fetches some files via http and ftp using LWP. I need to be able to see the throughput I'm getting in Kbps. Is there a more precise way to do this than taking a timestamp at the begining and end of the transaction and then using the elapsed time and file size to calculate the throughput? Perhaps someone can recommend a module for this sort of thing?

Replies are listed 'Best First'.
Re: Measuring Throughput for HTTP and FTP
by LTjake (Prior) on Nov 17, 2003 at 19:55 UTC

    Probably not exactly what you're looking for, but, check lwpcook's section on large documents. This will allow you to measure your throughput in an interactive manner.

    Here's a variation of the code give in the above link

    use LWP::UserAgent; use strict; my $url = 'http://www.w3.org/TR/xhtml1/'; my $agent = LWP::UserAgent->new; my $received = 0; my $start = time; my $res = $agent->request( HTTP::Request->new( GET => $url ), sub { my( $chunk, $res ) = @_; $received += length( $chunk ); printf( "%d%% - %d Kbps\n", 100 * $received / $res->content_length, $received / ( time - $start ) / 1024 ); } ); print $res->message;

    HTH

    --
    "To err is human, but to really foul things up you need a computer." --Paul Ehrlich