6 ms·
So why did they go with Go, a largely unproven language instead of Erlang? Seems like the right choice given what Disqus does.
by DiabloD3 14y ago
So why did they go with Go, a largely unproven language instead of Erlang? Seems like the right choice given what Disqus does.
- zemo 14y agoThe type system in Go is as important as the concurrency system. Sure, Erlang can do concurrency as well as (or better than) Go, but it doesn't have the type safety that Go offers.
- tptacek 14y agoCan it do concurrency better than Go? How so?
- pcwalton 14y agoFor one, a shared-nothing design makes migration to different machines easier and doesn't require a stop-the-world garbage collector. Erlang is memory safe in the presence of many-core (or many-system) parallelism. Go is not (you can segfault, possibly in an exploitable way, if GOMAXPROCS > 1). Erlang unbounded channels reduce deadlocks because your sender can continue execution without waiting for a receiver.
- tptacek 13y agoHave we heard a lot of stories about deployed Golang apps having problems because of garbage collection? It's true that this is a significant designed-in advantage for Erlang, which can run it's collector on a process-by-process basis. What's also true and potentially compensatory is the C-like degree of control Golang gives you over how you allocate memory and lay it out. I'm not sure the unbounded channel thing is a real advantage for Erlang. I'm happy to be convinced I'm wrong. What's a real, correct design which would be hard to realize in Golang (without unbounded channels) that relies on unbounded channels?
- pcwalton 13y ago> Have we heard a lot of stories about deployed Golang apps having problems because of garbage collection? It's true that this is a significant designed-in advantage for Erlang, which can run it's collector on a process-by-process basis. In general most Go apps that have been deployed are Web apps and server infrastructure, where concurrent garbage collection is not too much of a problem in practice. So Go's choice makes sense in Go's context. It does limit parallel scalability in some contexts—which of course are not the contexts that most people have been using Go for at this point. > What's also true and potentially compensatory is the C-like degree of control Golang gives you over how you allocate memory and lay it out. Go doesn't give you C-like control over allocation of memory. Language constructs will allocate memory in ways that are not immediately obvious, to quote Ian Lance Taylor [1]. It does give you control over layout of memory. > I'm not sure the unbounded channel thing is a real advantage for Erlang. I'm happy to be convinced I'm wrong. What's a real, correct design which would be hard to realize in Golang (without unbounded channels) that relies on unbounded channels? Suppose you're pulling down images from the network and printing out a sorted list of URLs of all the images you find. You might structure it as two goroutines A and B. Make two channels, "urls" and "done". Goroutine A is the network goroutine and simply crawls looking for images to stream to B over the channel "urls". When it's done it sends "true" on "done". Goroutine B is the sorting goroutine and first blocks on the channel "done" before it proceeds, after which it drains the "urls" channel and sorts the results. This program contains a deadlock due to synchronous message sends. If there are more URLs to be downloaded than the buffer size of "urls", then the program will deadlock. If "urls" were an asynchronous channel, however, this would be fine. Of course this can be structured to fix it, by doing the send in another goroutine for example (although that costs performance). But hopefully that's a good illustration of the subtleties of synchronous message sending. [1]: https://groups.google.com/forum/#!msg/golang-nuts/LoJJ1bICduA/AQFtD8_VI0sJ https://groups.google.com/forum/#!msg/golang-nuts/LoJJ1bICdu...
- tptacek 13y agoGo doesn't give you C-like control over allocation of memory. Language constructs will allocate memory in ways that are not immediately obvious, to quote Ian Lance Taylor [1]. It does give you control over layout of memory. These are two sides of the same coin. Having control over memory layout allows you to implement what are in effect allocators.
- karaziox 13y agogo func(){ channel <- data }() Here, you will never actually block on your send since it runs on it own goroutine. I can't see an actual use case for this kind of thing but since you are using this argument over and over then.. :)
- _ak 13y agoDo you have any sources on the exploitable segfault claim, or is that just FUD?
- tptacek 13y agoIt's mostly FUD, but it's a rathole of an argument since nobody has defined what "exploitable" means. Rather than nail down the term so we can all have ourselves an even more pointed language war, we should probably just let this go.
- pcwalton 13y agoSure. http://research.swtch.com/gorace http://research.swtch.com/gorace In general I consider segfaults exploitable, because of heap spray and virtual method calls. Even if not "exploitable", I consider it "very very scary".
- tptacek 13y agoThis is far fetched. The threat scenario that page contemplates is "what happens if you're trying to safely run untrusted Golang code, as if it was content-controlled Javascript and you were a browser". It's not the case that Golang in its natural environment gives attackers the ability to paint the heap with malicious addresses and then provide themselves with a statistically significant shot at corrupting memory to exploit those addresses. Your point is a reason that Golang couldn't be dropped in as a browser Javascript replacement. But nobody has ever suggested that it could be; it can't, just like Java (which was designed for the purpose but failed at it) and Erlang (which wasn't) can't.
- pcwalton 13y ago> It's not the case that Golang in its natural environment gives attackers the ability to paint the heap with malicious addresses and then provide themselves with a statistically significant shot at corrupting memory to exploit those addresses. What if a Go program allowed Go objects to be scripted by untrusted user code written in JavaScript? In browsers it is very possible to corrupt the Frame (Gecko)/RenderObject (WebKit) tree, which is in a C++ heap that is separate from the JavaScript heap. The memory safety issues in C++ are a problem not because they mean that untrusted code written in C++ can't safely be executed (although it does mean that). It also means that safe languages become easily weaponizable. JavaScript (or Lua, or whatever) embedded in a Go program could paint the heap with malicious addresses.
- MetaCosm 14y agoThe processes are first class and can be killed and monitored from the outside.
- zemo 13y agohonestly, I don't know. I know Go does concurrency well and I like it, the only reason I said it was equivalent or better was to avoid a flamewar. I've never even used Erlang.
- mattrobenolt 14y agoThe technical barrier for Erlang is much much greater in my opinion than Go. Introducing something into our stack is a very tricky situation. We are mostly all Python engineers, so bringing in something new has to be intuitive for others to pick up on and get involved.
- tptacek 14y agoHere are some potential reasons (I obviously don't know the actual reasons). You won't like any of them, but I hope you can take me at my word that I'm not a partisan (I have a passing familiarity with Erlang that comes of maintaining a Riak cluster, and I've built some fairly large projects in Golang, but my core languages are C and Ruby). * Golang has a more conventional, familiar, boring, "safe" language design than Erlang does. If your current language is Python, you're apt to find Golang congenial; I describe Golang to my friends as "a modernized hybrid of Python and Java". * Golang has a more flexible concurrency offering than Erlang. It has a very flexible (statically typed, sync-or-async) first-class channel type that you can deploy anywhere in a program whether you parallelize it or not. More importantly, it has first-class support for "conventional" shared-everything concurrency with mutexes and semaphores and whatnot. If you're designing everything from scratch to fit your language's preferred idiom, this may not matter, but if you're porting an existing design it might matter a great deal. * Golang has what I will perhaps hyperbolically refer to as first-class support for strings, with reasonably performant regular expressions, a clearly delineated "just a bag of bytes" type designed from scratch for high-performance buffering and packet framing/demux, and a sane approach to UTF-8 Unicode. It also turns out to be a very elegant framework (as imperative languages go) for building parsers, since you can put the concurrency stuff to work for it. These are common programming tasks and not one Erlang is well known for handling gracefully. * As I understand it, both Erlang and Golang have comparable lightweight process/thread/coroutine/whatever facilities. Golang was designed from the start to handle huge numbers of demand-spawned threads with small, dynamically allocated stacks. I'm not saying Golang does this better than Erlang does, but it might be tricky to argue that Erlang's process model is better than Golang's. * Erlang requires an installed runtime and executes in a VM. Golang produces native binaries. You can compile a Golang program on one machine, rsync that single binary to another machine that has never been blessed with a Golang installation of any sort, and run it without a problem. * Golang has modern, extremely high-quality tooling. Entire huge Golang projects rebuild in seconds or less. The compiler is extremely helpful. Code formatting and documentation are first class problems for the toolchain. The Go package system is well thought out, and, again, is familiar to Python programmers. Just some guesses as to reasons in there.
- genwin 14y ago
- plainOldText 14y agoI like Erlang a lot, but learning Go is much easier, especially for people with a background in imperative languages. When you code in Go everything seems very familiar, even for someone who tries it for the first time; in Erlang not so much. Now, don't get me wrong, I think it is amazing to know different paradigms, but some people just can't afford that luxury (think lack of time). There's probably no match for Erlang's error handling mechanisms out there, I actually dislike Go's panic mechanism, but if you have a small piece in your system which needs to be wickedly fast and highly concurrent I see Go as a perfectly good choice.
- voidlogic 14y agoObviously much depends on your specific program and use case, but it appears likely that Go may be faster and more memory efficient than Erlang for many uses: http://benchmarksgame.alioth.debian.org/u64q/benchmark.php?test=all&lang=go&lang2=erlang&data=u64q http://benchmarksgame.alioth.debian.org/u64q/benchmark.php?t... As always your program is the best benchmark.