ThomasDickey / original-mawk

bug-reports for mawk (originally on GoogleCode)
http://invisible-island.net/mawk/mawk.html
18 stars 2 forks source link

improve flushing of output #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593504

Original issue reported on code.google.com by dic...@his.com on 28 Jun 2012 at 10:44

GoogleCodeExporter commented 9 years ago
This can probably be fixed by using setlinebuf() when the output is
either a tty or a pipe.

Original comment by dic...@his.com on 1 Jul 2012 at 6:00

GoogleCodeExporter commented 9 years ago
However, see my comment in
https://bugs.launchpad.net/ubuntu/+source/mawk/+bug/382602

Original comment by dic...@his.com on 29 Nov 2012 at 1:36

GoogleCodeExporter commented 9 years ago

Original comment by dic...@his.com on 29 Nov 2012 at 1:45

GoogleCodeExporter commented 9 years ago
Since the (long-existing and documented) -W interactive option does
what is needed here, the functionality is already supplied.  Making
mawk use unbuffered I/O for stdout when it is a tty would detract from
its performance.  One could make this more/less transparent by reading
options from an environment variable (and I'll leave this issue open
to consider that approach).

Original comment by dic...@his.com on 1 Dec 2012 at 12:16

GoogleCodeExporter commented 9 years ago
Hello,

This is a buffered input problem and not an output buffering problem.  The "-W 
interactive" option tells mawk to return from each read rather than trying to 
fill up its input buffer and solves the problem.  One could argue that mawk 
should use unbuffered input when reading from standard in.

Also note that the call to "fflush" has no effect since standard out to a 
console is always flushed automatically.

Thanks.  Daniel Pettet

Original comment by daniel.p...@gmail.com on 12 Feb 2014 at 1:10

GoogleCodeExporter commented 9 years ago
That last part of the comment was inaccurate (stdout by default is 
line-buffered).

Original comment by dic...@his.com on 1 Aug 2014 at 8:13

GoogleCodeExporter commented 9 years ago
I'm not inclined to change the default (by turning on -Wi all the time),
because it would make mawk slower.  For instance, running the example
script with/without fflush with/without -Wi, and just looking at mawk's
timing (ignoring the sleeps), I see a 15% slowdown.

The fflush adds a little (oddly, fflush in mawk adds less than in gawk
or original-awk, according to my testing).

Turning on -Wi if the output is a tty might make sense.  However, the
example given does not output to a tty - it is to a pipe.

Original comment by dic...@his.com on 5 Aug 2014 at 11:24

stephane-chazelas commented 3 years ago

Original comment by dic...@his.com on 5 Aug 2014 at 11:24
I'm not inclined to change the default (by turning on -Wi all the time), because it would make mawk slower. For instance, running the example script with/without fflush with/without -Wi, and just looking at mawk's timing (ignoring the sleeps), I see a 15% slowdown.

You could however stop that input buffering (while leaving output buffering as is or line based if tty like most other utilities). mawk is the only utility that I know that does that. I suspect it's even counter productive. It's also very confusing.

See another case at https://unix.stackexchange.com/q/655796 today of yet another person scratching their head for hours trying to understand what's going on.