4 ms·
Erlang does not allow structural sharing. Sending large data structures to other processes always means serialization penalties, even if those processes run on
by amelius 5y ago
Erlang does not allow structural sharing. Sending large data structures to other processes always means serialization penalties, even if those processes run on the same CPU.
Also, was the Erlang VM written in Erlang? Probably not. So I'm skeptical about the universality claims of the language.
- mehwoot 5y agoAlso, was the Erlang VM written in Erlang? Probably not. So I'm skeptical about the universality claims of the language. The article states the opposite opinion: that you should use the right tool for the right job. Change the requirements... and the spectrum-of-ridiculousness for any option changes drastically. The language matters, deeply.
- mikl 5y agoThe source for Erlang/OTP is 71.6% Erlang: https://github.com/erlang/otp https://github.com/erlang/otp - but yes, some of the lowest-level parts are written in C. As for universality, not sure where you’re getting that. No one’s saying you should use Erlang for writing device drivers or OS kernels, or the lowest-level parts of the VM. Erlang is a medium- to high-level language, and should be evaluated as such.
- tomn 5y agoFurther, there's a meta-interpreter included in the standard library: https://erlang.org/doc/man/erl_eval.html https://erlang.org/doc/man/erl_eval.html https://github.com/erlang/otp/blob/master/lib/stdlib/src/erl_eval.erl https://github.com/erlang/otp/blob/master/lib/stdlib/src/erl... It's not lisp levels of concise, but the language was not designed for that.
- knome 5y ago>Sending large data structures to other processes always means serialization penalties, even if those processes run on the same CPU the trade off is that every thread has its own gc arena that can be freely and quickly cleaned, and even better, often simply dropped entirely when the thread ends there's never a stop the world moment, only the specific greenthread that's used up all its space. OTP setup for managing processes in a standard way is also a big boon to developing in the language. if you need to mangle some giant datastructure concurrently, sure, erlang is likely to not be what you need. but if you're just trying to toss out a cluster of interconnected nodes that can handle tons of concurrency and your interprocess messages are largely queries to threads dedicated to managing some resource or lump of data, it's a great setup.
- im_down_w_otp 5y agoThe original complaint also isn't true. Large binaries sent as messages actually end up reference counted and managed by BEAM that way. This is specifically to avoid expensive memory copies and fragmentation. I don't remember what the size threshold is off the top of my head anymore, but it's "large" by 1980's standards, not by today's. Something like 64 bytes.
- toast0 5y agoHeap binaries are limited to 64 bytes as you guessed, but to be pedantic, the limit isn't only for sending, anytime you make a binary larger than 64 bytes, it will be a RefC binary, which includes the at least 255 byte binaries that can get allocated for the append optimization. [1] This particular optimization can backfire if you're not careful. If you generate short binaries that trigger this optimization and then store them in ets, it references the existing binary which has a lot of extra space. If you hit that binary:copy/1 will return a perfectly sized binary you should store in ets instead. This same kind of thing can happen if you make a sub binary from some large binary (like a service response) and store it. [1] http://erlang.org/doc/efficiency_guide/binaryhandling.html#constructing-binaries http://erlang.org/doc/efficiency_guide/binaryhandling.html#c...
- jake_morrison 5y agoThat's incorrect, there is no serialization when sending messages to processes that are on the same machine. (Otherwise it's transparent to the application, though of course there are performance impacts.) To the programmer, messages are immutable. There are, however, optimizations to reduce the performance impact, particularly for binary data. When you send a binary message that is longer than 64 bytes, it is actually stored in a shared heap and effectively only a reference is passed as a message. Similarly, when you extract a small piece out of a larger binary, you might actually get a reference to the larger data stored on the binary heap. The Erlang VM has had more than 30 years of development, and there are a lot of subtle optimizations like this which were needed to solve real world performance and scaling issues. Lack of serialization is one thing that makes e.g. the ETS key/value store built into the VM nice compared to Redis. You can just use raw data structures as keys and values. Reads and writes are under 1 microsecond.
- dudul 5y agoThis is incorrect. Functional languages are usually really good at data sharing since they promote immutability. When messages are sent to a process, the data is shared as much as possible to avoid duplication.
- toast0 5y agoUnless you do exciting things with NIFs, Erlang can't share any data except for the binary storage for RefC binaries. When you send a message, all the Erlang terms are copied for the new process, but for a RefC binary, that means a new ProcBin that references the same binary storage, not a copy of the binary storage. This copying isn't memory efficient and may not be CPU efficient, but along with immutability, it makes garbage collection simple, fast, and independent per process.
- deleted 5y ago[deleted]
- ramchip 5y agoErlang doesn't share data between processes by default (except large ref-counted binaries) because it would cause GC pauses to be global, rather than per-process.
- di4na 5y agoNot only that, the original reason was that it makes crashing and concurrency far easier. I suppose crashing is a kind of GC