Skip to content

Some Thoughts on Go and Erlang

by on April 27, 2014

UPDATE: I’m seeing that I did not make the point of this post clear. I am not saying Go is wrong or should change because it isn’t like Erlang. What I am attempting to show is the choices Go made that make it not an alternative to Erlang for backends where availability and low latency for high numbers of concurrent requests is a requirement. And notice I’m not writing this about a language like Julia. I have heard Go pitched as an alternative to Erlang for not only new projects but replacing old. No one would say the same for Julia, but Go and Node.js are seen by some as friendlier alternatives. And no, Erlang isn’t the solution for everything! But this is specifically about where Erlang is appropriate and Go is lacking.

I’m going to attempt to leave out my subjective opinions for disliking parts of Go, such as syntax or lack of pattern matching, and explain objective reasons for the language and runtime not being fit for certain types of systems. But I’ll start with the good.

Where Go Shines

Clients

As Rob Pike wrote, his biggest surprise was Go is mostly gaining developers from Python and Ruby, not C++. To me this trend has been great to see. No more slow clients installed through pip or gems! (Though for some reason Node.js for clients is growing, wtf Keybase?)

Go provides developers with a fast and easy to use high level, statically typed language with garbage collection and concurrency primitives. It would be great for C++ developers to move to Go as well, the programs that crash constantly on my machine are proprietary C++ that love to misuse memory — Hipchat and Spotify. But Rob Pike pointed out that the C++ developers don’t want the simplified, yet powerful, world of Go. Ruby and Python developers, rightly, do.

Tooling

Getting up and going with building executables depending on third party libraries can be done easily without depending on third party tools, it all comes with Go. While the tools aren’t perfect, there are tools to fill in some gaps like Godep, it is still a huge win for the language.

Where Go Falls Short

Some of Go’s design decisions are detrimental when it comes to writing low-latency fault-tolerant systems.

Concurrency

Yes, I listed concurrency primitives as a plus in the first section. It is in the case of replacing Ruby or Python or C++ for clients. But when it comes to complex backends that need to be fault-tolerant Go is as broken as any other language with shared state.

Pre-emptive Scheduling

Here Go has gotten much better. Go’s pre-emptive scheduling was done on syscalls but now pre-emption is done when a goroutine checks the stack, which it does on every function call, and this may be marked to fail (causing pre-emption) if the goroutine has been running for longer than some time period. While this is an improvement it still lags behind Erlang’s reduction counting and newly added dirty schedulers for improved integration with C.

Garbage Collection

In Go garbage collection is global mark and sweep. This pauses all goroutines during the sweep and this is terrible for latency. Again, low latency is hard, the more the runtime can do for you the better.

Error Handling

This isn’t just about having no exceptions and the use of checking if a second return value is nil. Goroutines have no identity which means Go lacks the ability to link or monitor goroutines. No linking (instead using panic and defer) and no process isolation means you can not fall back on crashing and restarting in a stable state. There will be bugs in production and a lot of those bugs will be Heisenbugs, so being able to layout processes, isolated from each other but linked based on their dependencies, is key for fault tolerance.

And on top of these major omissions in dealing with faults Go has nil. How in 2014 this is considered OK I haven’t wrapped my mind around yet. I’ll just leave it at that, with a befuddled look.

Introspection

Not having a REPL is annoying for development, but no remote shell for running systems is a deal breaker. Erlang has impressive tracing capabilities and tools built on those capabilities like recon_trace. Erlang’s introspection greatly improves development as well as maintenance of complex running systems.

Static Linking

Yes, another thing that was also in the positives but becomes a negative when used in systems that are expected to be long running. While having no linking does means slower execution it gives Erlang advantages in the case of code replacement on running systems. It is important to note that due to Erlang’s scheduling and garbage collecting strategies many of these speed tradeoffs do not mean Erlang will be slower than an implementation in another language, especially if the Erlang implementation is the only one still running.

Code Organization

The OTP framework provides libraries for common patterns. OTP not only means less code to write and better abstractions but also improves readability. Following the OTP standards with applications, supervisors and workers (gen_server, gen_fsm, gen_event) means a developer new to the program is able to work down through the tree of processes and how they interact. Go’s channels, unidentifiable goroutines and lack of patterns to separate goroutines into separate modules leads to much harder code to reason about.

Can or Even Should Go Change?

Erlang has been around for decades and Go is the new kid on the block, so can Go improve in these areas? Some, yes, but most of it can not because of the choices made in the design of the language which were not fault tolerance and low latency.

This doesn’t mean Go is “bad” or “wrong”. It simply makes different choices and thus is better suited for different problems than a language like Erlang.

About these ads

From → Erlang

13 Comments
  1. brb permalink

    Are you sure about preemptive scheduling of go-routines? It gives back a cpu slice to the scheduler when it does some blocking call and the scheduler can’t preempt the routine which falls to the definition of co-operative scheduling.

  2. I usually do not drop many remarks, however I browsed a few of the responses on Some Thoughts on Go and Erlang | Erlware Blog.

    I actually do have some questions for you if
    it’s okay. Could it be simply me or does it look as if like some of the remarks
    look as if they are coming from brain dead visitors? :-P And, if you are writing at other places, I’d like to follow everything new
    you have to post. Could you list of every one of all your social community pages like your linkedin profile, Facebook page or twitter feed?

  3. Quality posts is the crucial to attract the visitors to pay a visit the site, that’s what this web page is providing.

  4. I visited multiple blogs but the audio feature for audio songs present at this web page is
    actually fabulous.

  5. Very good site you have here but I was curious if you knew of any forums
    that cover the same topics talked about here?
    I’d really like to be a part of group where I can get opinions
    from other experienced individuals that share the
    same interest. If you have any recommendations, please let me
    know. Thanks a lot!

  6. Thank you for sharing your thoughts. I really appreciate your efforts and I will be waiting for
    your further post thank you once again.

  7. Awesome blog you have here but I was curious about if you knew of any community forums that
    cover the same topics talked about in this article? I’d really like to be a part of community where I can get opinions from other experienced people
    that share the same interest. If you have any suggestions,
    please let me know. Thanks!

  8. I would like to thank you for the efforts youu have put
    in writing this blog. I’m hoping to check out the same high-grade blog
    posts by you in the future as well.In fact, yor creative writing abilities has inspired
    me to gget my own, personal site now ;)

  9. Hello my loved one! I want to say that this article is amazing, nice written and include almost all important infos.
    I would like to look more posts like this .

Trackbacks & Pingbacks

  1. Links & reads for 2014 Week 17 | Martin's Weekly Curations
  2. Some Thoughts on Go and Erlang | thoughts...
  3. CouchDB Weekly News, May 01 – CouchDB Blog
  4. [Erlang 0122] Erlang Resources 2014年1月~6月资讯合集 - 博客园

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: