[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Forcibly-unbuffered redirect-to-pipe yields terrible perf
From: |
alexandre.ferrieux |
Subject: |
Forcibly-unbuffered redirect-to-pipe yields terrible perf |
Date: |
Wed, 8 Feb 2023 23:46:33 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 |
Hi,
When writing into a pipe redirection:
gawk '{print | "cat > /tmp/foo"}'
... gawk *always* handles the pipe as unbuffered. This can be witnessed with an
external "tail -f /tmp/foo".
This makes gawk completely unusable for any heavy-duty multipipe output, as CPU
time is dominated by single-line write() syscalls.
By contrast, heavy-duty multifile output *is* supported:
gawk '{print > "/tmp/foo"}'
... is fully buffered. What is the logic behind this difference ?
Note: it can be traced to this commit:
3697ec5c Arnold D. Robbins Thu Jul 15 23:12:49 2010 +0300 Moved to gawk 2.11.
.. with the following comment:
Improved handling of output bufferring: now all print[f]s redirected to a tty
or pipe are flushed immediately and non-redirected output to a tty is flushed
before the next input record is read.
Before this commit, the programmer had the choice; they could call fflush() or
not, so that both "interactive" and "efficient" use cases were supported.
Afterwards, the choice has disappeared: any write to a pipe is deemed
"interactive", incurring a syscall, and terrible performance.
Can someone explain why this is an improvement ?
PS: I do realize this has been the case for 13 years. But maybe it wasn't
spotted before, precisely because Awk was too slow for such heavy-duty tasks,
back in the days. Now things are different: Awk is a serious candidate for
scientific computing, and such details are just starting to be a problem.
_________________________________________________________________________________________________________________________
Ce message et ses pieces jointes peuvent contenir des informations
confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce
message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages
electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou
falsifie. Merci.
This message and its attachments may contain confidential or privileged
information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete
this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been
modified, changed or falsified.
Thank you.