Interactive mini-book on concurrent programming in Go.
186 comments
Just from observations over the years, I don't think there's any other language quite like this, in terms of how things can end up happening in any thread.
Supposedly WhatsApp scaled to serving over 1 billion users with Erlang and BEAM.
RabbitMQ, used by Reddit, uses Erlang and BEAM.
Discord uses Elixer and BEAM.
I just traveled down the BEAM rabbit hole. Fascinating story. The Ericsson Computer Science Laboratory cranked out some amazing products in the early 1990's.
Their goal was five nines of reliability for Ericsson telephone switches.
According to Joe Armstrong (an interesting fellow from Ericsson), the AXD301 ATM switch achieved nine nines over a nine-month period using Erlang and BEAM in 2002. That calculates out to 24 milliseconds of downtime.
Hello, Mike.
Hello, Joe.
System working?
Seems to be.
Okay. Fine.
Okay.I think Go and the BEAM family languages are both great.
Truly something else if error handling is built into the language as a default case, not an … exception.
In Rust when receivers all drop, the producer will error instead of blocking, so Rust is better in this aspect.
I don't feel this is hacky or even a work around. Just different promises on what goroutines are vs threads/concurrency/processes in other languages.
Exit and panics are promised at the process level in Go.
Isn’t this also true of threads? I know you can usually cancel them from a thread handle, but that kills the thread ~immediately without cleaning anything up, right? Presumably you pretty much always want cooperative cancellation?
Stick to err/wait group and go routines and it's OK. Any PR with a channel or mutex I'll assume the author made a mistake.
[
"https://httpbin.org/delay/1",
"https://httpbin.org/delay/2",
"https://httpbin.org/delay/3"
]
|> Task.async_stream(
&Req.get!/1,
max_concurrency: 3,
ordered: true,
timeout: to_timeout(second: 2)
)
|> Enum.to_list()Doesn't that describe pretty much any green thread style concurrency implementation.
Other languages and their implementations of green threads usually have cooperative scheduling or M:1 mapping
Too many years of Java and managing Threads and Runnables probably rotted my brain.
I always ask/tell people to write without channels, and only add them when you have justification for doing so. That leads to much more sane code.
One pattern I see often because random blogs mention it is starting X long lived goroutines, then passing them data via channels, then receiving responses via channels, then handling. In my experience, it's 100x less error prone to just use a semaphore to start a goroutine per data, and have them do their own handling. No channels involved.
Spamming them all over the place is a red flag imo
One question though: your advice is to write things serially first before moving to concurrency, which for me is general programming common sense, but would you argue that once you start writing concurrent code then channels are not well suited compared to "good old" sync primitives (mutexes, etc.)?
Just how Go adding generics to the language didn't magically fix the billions lines of non-generic Go code, adding virtual threads to Java didn't update its entire ecosystem to take advantage of them.
Meanwhile, the entire Go ecosystem from the beginning took advantage of goroutines, so all code you'll ever interact with will have excellent support for them.
superior how -- What does it do better over Go channels in your opinion?
Goroutine leaks in prod are no laughing matter. They are difficult to debug without killing the process, and that's only useful if you are sure you're going to get stderr to get the full traces of all goroutines.
Read the full thread on Hacker News →
Related stories
- Go concurrency distilledantonz.orgLobsters · 48 points · 4 days ago
- The Verge · 0 points · 5 days ago
- Ars Technica · 0 points · 9 days ago
- Hacker News · 1 points · 10 days ago
- Hacker News · 277 points · 10 days ago
- The Mac Mini is still mighty, just not as cheaptheverge.comThe Verge · 0 points · 9 days ago