PragTob
I ran into an interesting problem recently where simple concurrency on the BEAM via Task.async made my application a lot slower and a lot more memory hungry. This blog post illustrates the issue with a short example, where processing 3 non-trivial actions on a list in parallel is slower than doing it sequentially, and then explains why this happens and what can or can’t be done about it.
Trending in Blog Posts
Hey folks,
I just published a post about Hologram’s funding and where the project goes next - the short version:
Curiosum as Main Spons...
New
Hey everyone! :waving_hand:
I’ve published Part 7 of the Building Distributed Systems in Elixir series, where we build core distributed ...
New
An educational side project in Elixir, Phoenix, and Tauri. I share what I learned while wiring Automerge into the BEAM, including how I s...
New
So, instead of wasting my afternoon arguing with anonymous handles on X, I turned to my trusty, soulless assistant and said: “Listen, ple...
New
Process labels are useful for visualization and debugging. Here’s why you should use them.
New
New article: Elixir Project Structure — From mix new to a Growing Codebase
I’ve published a new article in my Elixir learning series on d...
New
What happens if you design tools for LLMs instead of letting LLM use human tools ?
Wrote a blog on why and what that enables.
As I see ...
New
Other Trending Topics
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
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
D4no0
Using the term parallel in this context is incorrect, the correct term would be concurrently and this has some very important implications:
PragTob
@D4no0 I disagree, parallel is the correct term here or why wouldn’t it be? Yes there is no guarantee that they will all run at the same time - but with 24 available cores and the schedulers otherwise unoccupied I’m pretty certain they will. Unless you intend to make the argument that nothing on the BEAM ever runs in parallel or what am I missing?
There is definitely nothing that absolutely stops them from running at the same time, making it concurrent.
D4no0
If you are not certain 100%, then you cannot claim that your tasks are running in parallel. IMO a setup where this is enforced in all cases is in order to validate parallel claims and benchmarks.
dimitarvp
To be fair, that wasn’t very surprising. Parallelizing in such a manner only saves time when (1) there’s lots of it (not just 3 tasks) and (2) the data is not being carried around but is crunched into much smaller pieces and/or sent off to other systems (Kafka, Postgres et. al.).
But the article was informative and interesting, and I thank you for it.
dimitarvp
Come on now. Unless you have a strict one-thread-pinned-per-core runtime then you can’t claim it for any runtime, Golang’s and Rust’s
tokio’s included.Fact is that most parallel runtimes do parallelization on a best-effort basis and they do a damn good job at it. There was a rather hilarious article a while ago reposted on HN how the Linux kernel never used more than 4 (or 8?) cores for a while, some years ago. What can a runtime do if the kernel is lying to it? But that’s a separate topic.
So… 100% guarantee? No, but it’s at least 90%.
D4no0
It still doesn’t feel right to me using this term so freely, there is a reason parallel programming (for example cuda development) is an entire different paradigm with completely different concepts.
dimitarvp
Maybe, but my goal is not a strictly academic discussion.
warmwaffles
Unbounded parallelism is generally not a good tactic. Your workload and underlying hardware capabilities should be well understood to help determine how concurrent you want a set of tasks to go.
PragTob
@D4no0 Technically it executed in parallel if at any point in time during that time 2 bits of code ran at the same time. If you think that for almost 4 minutes of run time with 24 schedulers available to erlang (and 12 physical cores) this didn’t happen then that’s some next level. Of course, it happened more than that and you could look at CPU utilization. You can always make an argument that “maybe it didn’t actually execute in parallel” even with the OS scheduler.
Most of that is beside the point though, what’s important is showing how the runtime, by default not some weird configuration, handles these work loads and what to do accordingly.
@warmwaffles The parallelism here wasn’t unbounded though right - I mean the first example explicitly has 3 tasks.
That said, of course you’re right - which is why I always advocate to benchmark things instead of assuming what’s faster/better as there are many surprises on the way
PragTob
Totally! It was just a stupid example I made up to try and easily illustrate in a benchmark the problem I ran into with benchee to show-case it without all the context and overload of benchee.
edit: sorry for multi reply, tried to fold it into one again but couldn’t see how to delete this one