When you write to the pipe, the other program won't get anything until the pipe's buffer (4096 bytes) fills.

Many of your slow, short line inputs will be read into a buffer as a single unit, and will then be timestamped as they are read (as lines) from the buffer. Since reading lines from a buffer is very fast, the timestamps will be very close together for each buffer load of lines.

The effect is that the perl script gets bursts of input all very close together, but then a long gap until the buffer fills again. To demonstrate this, I fed a file with timestamps once a second lke this:

perl -MTime::HiRes=time -E"$|++;say scalar localtime while sleep 1" | tee junk.log Fri Feb 5 22:42:58 2010 Fri Feb 5 22:42:59 2010 Fri Feb 5 22:43:00 2010 Fri Feb 5 22:43:01 2010 Fri Feb 5 22:43:02 2010 ...

And then tailed the file and added a second hires timestamp like this:

tail -f junk.log |perl -MTime::HiRes=gettimeofday -E"$|++;say gettimeofday().' '.$_ +while <>" 1265410130.569 Fri Feb 5 22:46:07 2010 1265410130.56927 Fri Feb 5 22:46:08 2010 1265410130.5694 Fri Feb 5 22:46:09 2010 1265410130.5695 Fri Feb 5 22:46:10 2010 1265410130.56959 Fri Feb 5 22:46:11 2010 ... 1265410131.50094 Fri Feb 5 22:48:46 2010 1265410131.50917 Fri Feb 5 22:48:47 2010 1265410131.51604 Fri Feb 5 22:48:48 2010 1265410131.52273 Fri Feb 5 22:48:49 2010 * End of first buffer full 1265410294.569 Fri Feb 5 22:48:50 2010 *** Start of second buffer ful +l 163 seconds later 1265410322.694 Fri Feb 5 22:48:51 2010 1265410322.69411 Fri Feb 5 22:48:52 2010 1265410322.69423 Fri Feb 5 22:48:53 2010 1265410322.69432 Fri Feb 5 22:48:54 2010 1265410322.6944 Fri Feb 5 22:48:55 2010 ... 1265410322.97337 Fri Feb 5 22:49:39 2010 1265410322.98039 Fri Feb 5 22:49:40 2010 1265410322.98775 Fri Feb 5 22:49:41 2010 1265410427.993 Fri Feb 5 22:49:42 2010 Terminating on signal SIGINT(2) 1265410427.998 Fri Feb 5 22:49:43 2010

As you can see, the data written to the file over a period of 3 minutes, actually arrives at the perl script in just a couple of seconds--but delayed by nearly 3 minutes. Then there's another 3 minute delay before another burst arrives in just a couple of seconds. It's all down to the buffering done by the pipe.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

In reply to Re: Time::HiRes strange behavior by BrowserUk
in thread Time::HiRes strange behavior by golden.radish

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.