I’ve created a new repository on GitHub to compare the fairness and real-time performance of schedulers in Erlang and Go. Feel free to check it out!
This repository contains a comparative analysis of the scheduling fairness and real-time performance between Golang and Erlang. The tests demonstrate that Golang’s goroutine scheduler performs poorly - it’s crude, unfair, and lacks good real-time characteristics. In contrast, Erlang’s scheduler proves significantly superior in both fairness and real-time performance!
In Go, whether Fibonacci is implemented recursively or not, as long as the code of function work1 and function work2 is the same, work1 and work2 should be treated fairly, ensuring that their execution counts remain close.
Why should this make a difference. You would expect the real-time handling to be able however things are done in Golang code. Otherwise it is a very “unsafe” handling if I am forced to write my code in a specific way for it to work.
Yes, you are right. Golang’s scheduler should strive to treat each goroutine fairly and allocate time slices equitably. However, in reality, its scheduler cannot achieve complete fairness and real-time performance, which is why the execution counts of work1 and work2 have ended up differing.
I don’t know much about Go runtime, but Concurrent Haskell runtime (GHC), for example, yields on heap allocation. That illustrates how minor benchmark implementation details, like whether to use a loop or recursion, could be relevant for scheduler fairness comparison.
But from non-technical perspective, if you want to make a convincing pro-Erlang argument to Go developers, it’s worth comparing idiomatic code vs. idiomatic code to show the superiority of BEAM scheduler. Otherwise it’ll be easy to dismiss.
Although it is not a comprehensive comparison between the schedulers of Golang and Erlang, in this test code, the work1 and work2 functions include not only recursive calls to fib, but also some CPU intensive calculations such as sha256. So at least in this use case, it can still demonstrate the superiority of the Erlang scheduler. By the way, testing should not consider too many so-called idioms. As long as the compilation is successful, it can run, the syntax and semantics are legal, and there are no crashes, then this test case should be recognized.
Moreover, this test code does not compare the absolute difference in execution times between Golang and Erlang, but compares the execution times of work1 and work2 within the same language. Therefore, it can logically prove the fairness and real-time performance of the schedulers of each language.