<story><title>Goroutines, Nonblocking I/O, and Memory Usage</title><url>https://eklitzke.org/goroutines-nonblocking-io-and-memory-usage</url></story><parent_chain></parent_chain><comment><author>atombender</author><text>It always struck me as odd that Go has select{}, but no way to select on a file descriptor such a socket. There&amp;#x27;s literally no way to poll a file descriptor: You have to read from it, and deal with the result.&lt;p&gt;That also means reads aren&amp;#x27;t interruptible (unless you count closing the descriptor as interrupting, which is a blunt hammer indeed). AFAIK the only way to do this is to set SetReadDeadline() on the connection to a smallish value, then let the interrupter block on a channel that&amp;#x27;s invoked when the deadline is reached.&lt;p&gt;Go&amp;#x27;s concurrency model is pretty friendly, but it&amp;#x27;s also unfriendly in many surprising ways. (Don&amp;#x27;t get me started on the whole nil channel thing, or the problem of channel closure&amp;#x2F;ownership, or channel performance overall.) It doesn&amp;#x27;t surprise me the least (while it did surprise the Go team) that Go fell flat among the C&amp;#x2F;C++ system programmer demographic.&lt;p&gt;Anyone want to chip in about how Rust, Swift and Nim compare here (regarding the article)?</text></comment>
<story><title>Goroutines, Nonblocking I/O, and Memory Usage</title><url>https://eklitzke.org/goroutines-nonblocking-io-and-memory-usage</url></story><parent_chain></parent_chain><comment><author>twotwotwo</author><text>It&amp;#x27;s true goroutines waiting on the network are going to sit on a few KB (small stack, buffer, user-mode sched bookkeeping), and if you multiply that out by a million or something you&amp;#x27;re talking gigs. But I think much of the appeal of the standard Go way, and similar approaches in other languages, is you can write more or less as if you were doing simple synch I&amp;#x2F;O, and the runtime work that other folks have done gives you something decent with AIO, small stacks, user-space thread switching, etc. without you having to think much about it.&lt;p&gt;I think the author says something similar put differently in the first paragraph.&lt;p&gt;Something like rakoo&amp;#x27;s trick is interesting, with the caveat zzzcpan added that it takes at least a tiny buf, not zero-len, but if you don&amp;#x27;t actually hit this wall I&amp;#x27;d charge forward the regular way.</text></comment>