Parallel concurrent comparison of Erlang and go

Source: Internet
Author: User
Tags try catch
This is a creation in Article, where the information may have evolved or changed.

When it comes to concurrent, Erlang and the go language are common, and the main feature of both languages is that Concurrent,erlang has a history of more than more than 20 years and is a language invented to simplify the development of telecom concurrency and high reliability applications. Go is the design of Google from 2007 onwards, 2009 OpenSource out, go belongs to a system Language,opensource even these two languages, the company's private language has a TNSDL,SDL variant, Previously wrote an article on the SDL and Erlang comparison (http://bookjovi.iteye.com/blog/1233299), these three kinds of concurrent languages are different, see below:

1) Language Design

The implementation of Erlang is based on the virtual machine Beam,go is a compiled language, with a single compiler (unlike Gcc,go very good to solve the problem of dependency, so when compiling the GO program does not need to compile the C program as specified in the Include and library), TNSDL and go are similar, belonging to native execution. Erlang and TNSDL are primarily for carrier-grade applications, while Go's concurrent is more versatile, mainly in the design of concurrent, where Erlang and SDL pass a message between process, And go is goroutine composition, plus channel,go by the process and message decoupling makes go design more versatility and flexibility, the application can decide whether or not to need channel processing according to their own needs. The routine plus channel design is also available in stackless python (some say go = C + stackless python), which is the flexibility of the channel so that go does not need to be returned in the Pid,go in Erlang, The spawn in Erlang returns the PID.

Erlang does not control the message buf, and using the Go channel can control the Capacity,make of the channel (Chan int, 100)

2) Library Support

Erlang has a history of more than more than 20 years, and various behavior,driver support in OTP makes using Erlang handy. The history of Go is much shorter and the library is still lacking.

3) Scheduler Scheduler

From an implementation perspective, each process in Erlang has its own heap, so it is not possible to share memory, in general the scheduler of Erlang is very similar to the Linux kernel, and go and SDL belong to native, which focuses on fairness, Each process in Erlang has a reduction, similar to the time slice,go of the process in Linux kernel is native execution, so how does go runtime control the fairness of each goroutine? The answer is no, the goroutine that native executes cannot guarantee fairness like Erlang, Goroutine can only have the opportunity to re-execute schedule functions in Syscall, IO, channel Read write operations. To perform the rest of the goroutine. In concurrent language, it is very important to solve the problem of fair scheduling and priority scheduling.

Given that go is not too mature, maybe there will be improvements later, scheduler and GC have a lot of discussion, now scheduler implementation logic and its simple (G & M), compared to the Erlang Scheduler is more simple (there are some bugs, but also the question of fairness).

Erlang Scheduler is located at: otp/erts/emulator/beam/erl_process.c

Go Scheduler located in: GO/SRC/PKG/RUNTIME/PROC.C

4) memory model

Each process in Erlang has its own heap,stack at the bottom of the heap, where the stack is a stack of Erlang process, similar to the operand stack in Java, stack down, stack top encountered heap top , the stack is moved to a new place after GC,GC.

Go is native execution, Goroutine stack is segment STACK,TNSDL runtime is also using this segment Stack,segment stack is a program that has a lot of stack execution, Stack switching is achieved through SETJMP,LONGJMP. (One of the main applications of setjmp and longjmp is concurrent, and the other is simulating try catch in C)

5) GC Garbage collection

Erlang's GC is a generational algorithm, with an old heap, with minor GC and full sweep, which is generally similar to Java, except that Erlang does not have the mark process and finds all eterm on the newly allocated heap directly according to Rootset.

Go is now Mark-sweep and will later use IBM's low-latency GC algorithm.

6) High Reliability

Erlang has a builtin of high reliability, such as link and monitor mechanism.

Go is a universal design, although the link and monitor,goroutine without built-in can use defer to achieve the effect of link.

7) Performance

One of the real goals of Go is high performance, which is why go is a compiled language. Theoretically, the performance of Goroutine is better than Erlang's process, but performance in software design principles is only one of the metrics, not all.

Well, talk too much, that's it, individuals still like go design, the future of programming language should be like go and Erlang throw away mulitthreading design (Java,python), At the same time, the use of the channel makes go practical more versatile and flexible, which is the concurrent language is accepted by the industry is very critical factor.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.