5 ms·
Interesting, looks like they've made progress on this: https://code.google.com/p/go/issues/detail?id=543 https://code.google.com/p/go/issues/detail?id=543 Als
by davidw 13y ago
Interesting, looks like they've made progress on this:
https://code.google.com/p/go/issues/detail?id=543 https://code.google.com/p/go/issues/detail?id=543
Also, from the article:
> Go garbage collector requires that all threads are stopped when running a collection and that memory must be in a consistent state.
People often ask about how Go differs from Erlang. That one's a fairly large difference under the hood. Erlang does GC on a per process (Erlang process, not OS process) basis.
- Roboprog 13y agoSo, does that mean it's safe to say that Erlang must copy the memory of values sent as messages between processes? Or, is there some kind of locking of such (aliased) message data???
- voidlogic 13y agoI would think so unless it stores all message bodies in shared memory and protects them with an enforced COW policy to begin with, or better yet does this with virtual memory with some clever COW mmapping.
- JulianMorrison 13y agoMessages are deep-copied in Erlang. There are other techniques possible such as uniqueness types, which allow "transfer of ownership", Rust uses those but Erlang does not.
- lpgauth 13y agoThat's not exactly true... in Erlang, any binary with size > 64 bytes will not be copied. Instead a pointer to a shared memory area will be passed.
- cpeterso 13y agoIf pointers are sent between Erlang processes, how does the per-process GC work without stopping the world?
- JulianMorrison 13y agoBig binaries (which yeah, I forgot about) live off to the side and are not GC'd. They're ref counted.
- masklinn 13y ago> So, does that mean it's safe to say that Erlang must copy the memory of values sent as messages between processes? Theoretically not since Erlang data structures are immutable, but outside of binaries which seat in a shared global heap the benefits was never considered to outweight the complexity costs (aliasing analysis and others), so messages are copied indeed.
- krobertson 13y agoI hadn't looked at that issue before, but have definitely been bit by it. On our main codebase, we experienced some major issues when moving from Go 1.0 to 1.1 from this exact issue. We had a goroutine that was doing some remote calls wrapped with a timeout, and the call was consistently timing out even though the remote service was perfectly fine (it was another service on the same box). We found the cause was another goroutine running something in an for loop that didn't do anything that would allow a pause in execution for another goroutine. So, the scheduler just obsessed on that goroutine, running none of the others until that one was done, and by then the timeout on the remote call had expired. We fixed up that case, but also found a few others were we simply added a very small sleep call... for no other reason than allowing the scheduler to evaluate other goroutines. Meh. It made sense when we finally tracked it down, but was one of those things where we had to pause and ask "really?"... and adding a sleep call with comments "yes, I am really calling sleep".
- georgemcbay 13y agoWhile it would be nice if the programmer never had to worry about this situation in the first place, when confronted with something like this I use runtime.Gosched() rather than a sleep call to yield. It more directly performs what you're attempting to do and is much more clearly self-documenting for situations where you really don't need to sleep for whatever period of time but do need to yield.
- krobertson 13y agoI hadn't seen runtime.Gosched() before, will take another look at it. Mentioned it to a coworker and they already knew of it, so maybe it was always switched to call it instead of sleep. :)
- tptacek 13y agoI had what I think was a related problem with file descriptor retention in timeouted socket code when writing a simple portscanner in Golang; I had to implement simple time-based flow control to give the runtime time to collect file descriptors, or I'd run out of them.
- 13y ago