4 ms·
It is best to treat the linked paper (Fibers under the magnifying glass) as a review of some implementations of fibers and not a repudiation of fibers in genera
by sseth 7y ago
It is best to treat the linked paper (Fibers under the magnifying glass) as a review of some implementations of fibers and not a repudiation of fibers in general. In particular, for this paper to apply to golang, several things would need to change :
Memory footprint : It says fiber user stack is 1 MB and so fibers have comparable memory footprint to threads. This is not true for goroutines which typically use a 4K stack.
Context switching overhead : gives numbers for architecture, but goroutines do not use the expensive switching instructions listed in the paper. Instead golang basically saves just the PC, SP and DX registers, significantly reducing the overhead.
Dangers of N:M model : The dangers mentioned of corrupting memory etc is specific to C++ libraries and do not apply to golang.
Dangers of the 1:N model do not apply to goroutines either.
My conclusion from the paper is as follows : Fibers are bound to fail as an OS feature, or as a library. To make fibers work you need to do what golang does i.e. make it part of the language with compiler support to reduce the context switching overhead and the memory footprint. You will however, pay a price in higher FFI cost. That may be a tradeoff which may or may not work for you, depending on the nature of your application.
- bullen 7y agoBut if coroutines can't share memory without copying; they don't allow you to scale (in parallel on one task across cores efficiently). What is then the purpose of coroutines as opposed to just having more machines? OS threads can scale (ipootace^), but then you need proper concurrent data structures and a complex memory model below to support them. Does go have those?
- sseth 7y agoGoroutines can share memory without copying.
- dickeytk 7y agoIf you watch just one video on Go, even if you don’t plan to ever write Go and just want to learn about it. Make it this one: https://blog.golang.org/concurrency-is-not-parallelism https://blog.golang.org/concurrency-is-not-parallelism It explains in detail how this is possible.