H

Hamidreza Soleimani

hamidreza-s.github.io · Personal blog · on HN since 2015

Hamidreza Soleimani writes technical explanations of how the Erlang VM handles garbage collection and process scheduling.

What HN saysHN commenters link it for Erlang memory layout and scheduler details, using it to discuss message copying, preemption, and how the BEAM stays responsive.
18HN people shared it
12linked it in comments
6stories submitted
635story points
2 years agolast shared
2015people per year2026

Most-shared posts

  1. 1
    Erlang Garbage Collection Details and Why They Matter
    10 people · 295 points · first shared 2015 · 45 comments on HN
  2. 2
    Erlang Scheduler Details and Why They Matter
    8 people · 340 points · first shared 2016 · 30 comments on HN

What HN people wrote when they linked it

sb8244 · 2018-04-15
I don't believe everything is shared like this. Anything smaller than 64 bytes is copied around to different process stacks. https://hamidreza-s.github.io/erlang%20garbage%20collection%20memory%2… Is a great post
devbug · 2016-04-07
This unfortunately breaks down with (bad acting) NIFs. Thankfully you can mark 'em as the dirty evil little things that they are (with negligible overhead): ERL_NIF_DIRTY_JOB_CPU_BOUND. [1] I implore anyone interested in Erlang or its surrounding languages, to read its source code. [2] More specifically, the BEAM. I'll warn you that it's very 80's hackeresque, but in a good way. Incredibly pragmatic. The way they achieve their world-class scheduling? Tip: not via a perfect theoretical design cooked up in some comp-sci lab. [3] If you've been following game engine design within the last 9 years or so, you'll probably have a good idea of how they do it. [4][5] [1]: https://medium.com/@jlouis666/erlang-dirty-scheduler-overhead-6e1219dc… [2]: https://github.com/erlang/otp/tree/maint/erts/emulator/beam [3]: https://hamidreza-s.github.io/erlang/scheduling/real-time/preemptive/m… [4]: http://blog.molecular-matters.com/2012/04/05/building-a-load-balanced-… [5]: There's a hell of a lot of depth to this problem domain. Charles Bloom's guiding principles for Oodle are spot, and well worth a look.
isaacsanders · 2023-04-01
davydog187 · 2018-08-02
The BEAM is a preemptive VM. That means that no one long running process can hog resources. The BEAM was built on a principal of responsiveness since it was originally designed for telephonics. Here's an in depth article on preemption in the BEAM that I shared with a friend this morning https://hamidreza-s.github.io/erlang/scheduling/real-time/preemptive/m…
lliamander · 2018-03-06
I wouldn't say you are doing anything wrong (or, at least I couldn't say that for certain without knowing more about your problem domain :) ). However, I also don't think you have to worry about the message payloads being too large. In Erlang, normally objects are copied between processes. However, for large objects (>64 bytes) they are put in a shared heap, and only the pointers are copied between processes[0]. [0] https://hamidreza-s.github.io/erlang%20garbage%20collection%20memory%2…
qohen · 2016-08-08
I don't know how the Erlang GC works so I can't really comment on that If you're interested, here are a few helpful blogposts on the subject: - This is a pretty short and readable post, though it's a bit old (2008): "Garbage Collection in Erlang" [0] - A more detailed (and recent -- 2015) blogpost: "Erlang Garbage Collection Details and Why It Matters" [1]. - And this is the most up-to-date description, from April 2016 concerning Erlang R19, by Lukas Larsson, who works on the Erlang VM -- it is long, but well-written and has nice illustrations [2]. [0] http://prog21.dadgum.com/16.html [1] https://hamidreza-s.github.io/erlang%20garbage%20collection%20memory%2… [2] https://www.erlang-solutions.com/blog/erlang-19-0-garbage-collector.ht…
andrewmutz · 2015-10-15
I believe large objects are on a shared heap. Source: https://hamidreza-s.github.io/erlang%20garbage%20collection%20memory%2…
asa400 · 2024-05-21
Briefly, the tradeoff that Erlang and its independent process heaps model make is that garbage collection (and execution in general) occurs per-process. In practical terms, this means you have lots of little garbage collections and much fewer "large" (think "full OS process heap") collections. This provides value in a few ways: - conceptually: it is very simple. i.e., the garbage collection of one process is not logically tied to the garbage collection of another. - practically: it lends itself well to low-latency operations, where the garbage collection of one process is able to happen concurrently to the the normal operation of another process. Please note that I am not claiming this model is superior to any other. That is of course situational. I am just trying to be informative. This is a good post with more information, if you're interested: https://hamidreza-s.github.io/erlang%20garbage%20collection%20memory%2…
dmitriid · 2020-08-16
(has been a while since I touched Erlang, so: grain of salt) There are several tricks that BEAM employs to work around these problems: - BEAM has dedicated threads to I/O, and system calls will happen on those dedicated threads. So, the green thread aka processes wil not be affected - (almost [1]) every call that happens "outside erlang" (that is it calls some code implemented in C inside the VM such as regexps etc.) is re-entrant. So the VM can and will re-prioritize tasks and put processes to sleep when needed and will re-start work when the process wakes up or some external work is done and the answer is received back So in theory all those stat() calls will be scheduled and queued on the separate prioritized I/O thread, the processes will be put to sleep until the result comes back, and then they will be awoken in turn. This may cause problems with the host OS though :) [2] [1] There are definitely places where code is not re-entrant yet, because you see updates in release notes from time to time, but most code is re-entrant because of reduction counting: https://news.ycombinator.com/item?id=14440205 and https://stackoverflow.com/questions/31751766/reductions-in-the-erlang-… and because schedulers can steal processes from each other: https://hamidreza-s.github.io/erlang/scheduling/real-time/preemptive/m… [2] A slightly unrelated anecdote: At a previous job due to some improper coding the web server would…
nathan_long · 2019-01-07
It's true that when Erlang was first made, machines were single-core, so parallel execution was not possible on one machine. However, the "no shared memory" process model made transitioning to true parallelism much simpler. The ability to run one scheduler per core was added around 2005 I think. See https://hamidreza-s.github.io/erlang/scheduling/real-time/preemptive/m… Also: > Erlang achieves concurrency by interleaving the execution of processes on the Erlang virtual machine, the BEAM. On a multi-core processor the BEAM can also achieve parallelism by running one scheduler per core and executing one Erlang process per scheduler. The designer of an Erlang system can achieve further parallelism by distributing the system on several computers. > https://happi.github.io/theBeamBook/ My understanding is that the BEAM will also do "work stealing" among schedulers to take better advantage of the available CPUs.
devxpy · 2018-11-11
It would be really cool to have the sort of Erlang-style processes in python -- where each process is a green process, so don't pay the cost of OS handling stuff, but at the same time you run multiple interpreters so that you still get the benefit of multiple cores [1]. Implementation-wise, this could be made simpler than removing the GIL, if we just fully give up on the concept of shared memory. (This is above my pay-grade, anyone with CPython internals knowledge, please share your thoughts!) I've been trying to build a shared state system over message passing that doesn't use shared memory at all [2], and I have experienced that OS level processes are a high cost to pay, when you try to do things the Erlang way, launching thousands of processes. [1] https://hamidreza-s.github.io/erlang/scheduling/real-time/preemptive/m… [2] https://github.com/pycampers/zproc

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close