We can do better than line-buffered output
Posted by zdw 1 day ago
Comments
Comment by Veserv 22 hours ago
Work-based flushing exists to batch work to amortize overhead. It allows you to tune how much time you spend in overhead in a work period. However, this can result in unbounded delay.
Time-based flushing targets a worst-case latency in low throughput environments. This ensures you do not get unbounded delays. Interestingly, this also allows you to tune how much time you spend in overhead in a work period.
So, with work-or-time based flushing what you are really tuning is how much time you are willing to spend in overhead in a work period and balancing that against latency.
As a nit, the article calls this a derivative of Nagle’s algorithm, but it is basically the opposite. Nagle’s algorithm is about batching until acknowledgement with no mention of time. In fact, the lack of time-based flushing in Nagle’s algorithm is why it interacts so poorly with TCP Delayed Ack.
Comment by JdeBP 17 hours ago
And since musl libc is in the news, it is worth nothing that musl's fwrite() is another of those that looks for the last linefeed in the buffer, rather than the first, and so should emit multiple lines in one underlying write(). Although this is only done in fwrite() specifically.
* https://git.musl-libc.org/cgit/musl/tree/src/stdio/fwrite.c#...
Comment by chuliomartinez 19 hours ago
From my horror cabinet: 1. Running count * on all sqlite tables 4x per second to show sync progress.
2. Progress bounce animation eating 80% of cpu (windows phone bizarro silverlight)
3. Sending myself 800 emails in 10 minutes…
The rule is quite simple, we are just bad at it. Computer to human communication should run at human speed.
Comment by abecedarius 22 hours ago
I've thought this was the right default for a good while. 50 years ago when Unix was designed, maybe not.
Comment by cowlevel 20 hours ago
We can also do better than terminals. 7-Zip was the GOAT.
Comment by jatoo 10 hours ago
Comment by ahartmetz 4 hours ago
Also, this:
> Where DEADLINE is something appropriate for human perception, like 100ms or so
is way off. You easily notice a hitch of one frame in 60 fps content, and this is comparable. The timer should be something like 1-10 ms. Outputting multiple lines is really fast, so even 1 ms would merge most output into a single write() call. I'd start with 1 ms and raise it if there's a strong reason, which there probably isn't.
Comment by edpenz 19 hours ago
Comment by ahartmetz 4 hours ago
Comment by phyzome 17 hours ago
Comment by wpollock 23 hours ago
Comment by usefulcat 23 hours ago
Comment by cassepipe 19 hours ago