Hello everyone!

I am a network field technician by day, and one of the sites I work on has a strange problem. The external Internet connection is about as stable as a tightrope walker on a tightrope in a dingy in a very violent storm. Quite a skilled one mind, because the connection doesn't actually go down, it just gets very slow every 3 seconds or so.

Enough of the back story. I'm trying to write a utility that will monitor the speed of a download over it's progress. I'm not interested in averages, which are comparatively simple to put together (just time a socket connection till it's finished, say) and can be done with tools like iperf. An average will just iron out the weirdness that I'm trying to detect.

At first I thought I could do something along these lines:
my $sock = new IO::Socket::INET->new( # open up a socket to the + testing server PeerAddr => 'vm1.naxxtor.com', PeerPort => '80', Proto => 'tcp', Type => SOCK_STREAM ) or die("Can't open socket $!"); print "Sending request\n"; print $sock $request; # send the request for th +e test file print "Starting transfer\n"; { local $| = 1; my $chunk_start = 0; # initialise some variabl +es my $chunk_time = 0; local $/ = \10240; # read in chunks 10240 b +ytes long $chunk_start = [gettimeofday]; # set initial timer while (<$sock>) { # loop through each chun +k $chunk_time = tv_interval($chunk_start); # calculate the time +taken to download this chunk. if ($chunk_time != 0) { push(@speeds,$chunk_time); } $chunk_start = [gettimeofday]; } }

Unfortunately this doesn't work - as sockets are BUFFERED, so if it recieves the data quicker than perl can get through the loop then you end up with a zero time for that chunk. It just goes plain screwy.

I have a horrible feeling I'm going to have to write this in C/C++ :(

What would probably work is to put a timestamp into a list for each chunk of 1024 bytes recieved, then process it later on. I can then do some windowing to get a reasonable estimation of speed at a particular point, and throw it out to a file which I can gnuplot.

I'm not sure. Any advice will be very well recieved :-)


In reply to Network Reliability Testing, problems with buffered sockets? by naxxtor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.