hassanRsiddiqi

hassanRsiddiqi

Cons of concurrency and synchronization in elixir?

I have read some beginner books and so many articles about elixir, and everyone was appreciating the concurrency & synchronization in elixir. But in my thinking everything has some pros and cons, everyone talked about the pros, but no one really mentioned the cons of concurrency & synchronization in elixir.

First 10 of 17 Posts Switch mode

hauleth

hauleth

The only con ai can think of is that concurrency is a lie. I mean, on many machines you will get concurrency, but in its nature, Erlang is parallel, not concurrent.

Other than that there isn’t much issues, maybe except the fact that many people think that throwing more processes at things will make things faster, which is obviously false.

xpg

xpg

In order to answer that question, I think we need to recap how Elixir/Erlang handles concurrency and synchronization: Isolated processes that communicate via messages, and general immutability of data.
If we leave ETS out of the equation for now, that means that nothing is shared between the processes.

When one uses multi-thread programming as a concurrency paradigm, the rules are different: Memory is shared, and one must ensure that this does not lead to trouble using semaphores or lock-free algorithms.

The disadvantage of Erlang’s approach is that someone has made a choice for you. You cannot easily share data between processes and you cannot easily implement your own lock-free algorithms.
So there are situations where it is not possible to achieve the same performance in Erlang as you can using multiple threads.

That being said. I think that in most cases the process-based model with messages being the way to exchange data between them, is vastly superior to threads.
The model has also been copied to many different languages and environments. Probably because it is much easier to work with, and because the drawbacks are few.

dimitarvp

dimitarvp

Obviously the con is when you absolutely positively need synchronization / barriers / semaphores / mutexes like in a normal DB engine.

Another con could be that the preemptive scheduling nature of the BEAM loses some CPU cycles to achieve the godlike responsiveness of the runtime. People working with lower-level languages, especially Rust lately, are efficiency fanatics and disagree with that tradeoff. (Although some that I have worked with admitted that the Erlang’s idea of processes with isolated mailboxes would kill 90% of the bugs they encountered in their code.)

sb8244

sb8244

Author of Real-Time Phoenix

I’m a big fan of cons included when there’s a bunch of pros. However, I was racking my brain a bit to think of practical cons with the approach in Elixir.

For me, efficiency is not necessarily a practical con because I wouldn’t say I was ever hindered by the parallelism of Elixir. But I can appreciate the approach it takes having an overhead and people considering that a con.

To me, maybe the biggest con is that parallel and synchronous code are something that can trip people up. It’s not this magical system that prevents coding or understanding errors. A person may think some code is parallel but then it converges into a synchronous choke point because they missed something.

ityonemo

ityonemo

Speed. Erlang (and elixir) are opinionated about how to achieve concurrency. Those opinions cost you processor speed. It’s not much, bit it’s real. Your elixir will never be as fast as go or java (but it will be faster than python or ruby).

For most people if they think they will need cpu speed are fooling themselves. It is no longer the 90s (or earlier) The bottleneck is usually somewhere else.

dimitarvp

dimitarvp

That’s frankly a selling point to me. I wouldn’t put Elixir in a competition versus Go or Java or Rust. However, Elixir does seem to be one of the fastest dynamic languages out there (and I mean top 10, if not 5 even).

So in its segment Elixir is quite impressive in terms of speed.

Qqwy

Qqwy

TypeCheck Core Team

Could you clarify this? The terms ‘parallel’ and ‘concurrent’ are often confused and there is also some middle ground for which people disagree over whether it falls under one or the other.

To my knowledge, paralellism = doing the same task many times side-by-side (on slightly different data) whereas concurrency = doing different tasks at the same time.

LostKobrakai

LostKobrakai

That’s not the difference.

Concurrency: Interweaving the completion of multiple tasks, instead of completing one after the other. (Works on a single core machine)
Parallelism: Doing multiple tasks at the same time (needs multi core)

Qqwy

Qqwy

TypeCheck Core Team

These two definitions I know under the terms multitasking (interweaving multiple tasks on a single core) and multithreading (doing multiple tasks at the same time) respectively.

EDIT: I stand corrected. The definition you mention seems indeed very common and probably is ubiquitous. I should have a talk with my parallel computing professor from back in the day, he did not explain it very well.

hauleth

hauleth

It is important to remember, that you need concurrency to make things parallel, but you do not need parallelisation for concurrency.

Where Next?

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91561 914
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement