vfsoraki
I am trying to do some works concurrently. The current code speaks for itself:
@sources
|> Flow.from_enumerable(max_demand: 50, min_demand: 20)
|> Flow.map(fn {mod, fun, args} = mfa ->
Logger.debug(fn -> ~s(Running #{inspect(mfa)}) end)
end)
|> Stream.run()
Basically, I am trying to run a map operation in parallel.
Some questions:
- Does this map
@sourcesin parallel using 50 workers? - Is this the right way to use Flow? I read the docs, and they mentioned partitioning to achieve better performance, but I don’t quite get if it is useful in my case.
- Is there any other mature library for this kind of tasks? I am already using
GenStageso don’t mention it. I think it’s an overkill to startGenStagefor some temporary, periodic work (Am I wrong?).
Trending in Questions
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
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
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #security
- #elixirconf-eu
- #processes
- #api
- #forms
- #hex










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
I don’t know how complex your mapping function is but to me
Flowand evenGenStageseem to be an overkill for the simplified scenario that you presented. EspeciallyGenStageis basically only necessary when you want to have back-pressure (namely consumers to be able to inform the producers that they are giving them work too fast).Have you tried with
Task.async_streamand controlling its maximum concurrency?vfsoraki
Nothing too complex, some ordinary HTML fetch and parse thing.
How come I have never seen
Task.async_stream? Seems like exactly what I needed.Anyway, what I did with Flow at first was wrong, here is a version that works in parallel:
I know, 20 stages are a bit high, but my work is mostly IO bound.
vfsoraki
Just for the sake of it, this is the same thing using
Task:I used supervisor and no linking version, because tasks could fail sometimes.
But I think the Flow is more beautiful, and since I’m already using GenStage somewhere else (processing infinite stream of data), having Flow wouldn’t hurt that much.
One thing about
Task.Supervisor.async_stream_nolinkbothers me, why arguments start with supervisor name and not the enumerable? Seems unnatural.dimitarvp
Oh well, it can happen.
Important thing is you know about it now!
If that is indeed the case then you are better off using
Task.async_streamand manually tune its concurrency parameter to see how much I/O plus CPU load your work can tolerate. IMO if you’re mainly I/O bound then using the default behaviour ofTask.async_streamwill leave your CPU under-utilised so definitely use a higher concurrency!Recently I was exercising importing CSV data into a DB from a public dataset. And I actually had to increase my DB pool from 10 to 20 (my CPU’s virtual core count is exactly 20), and instead of putting records one by one in the DB, I used chunking and then inserting records in those chunks (I chose 500 at a time). And this was multiplexed over all CPU cores and I was able to achieve about 90% load on all CPU cores.
In short, Elixir gives you everything you might need for your work but you have to make sure you properly load your machine.
ityonemo
Because the module is Task.Supervisor. The convention in Elixir is that if you are calling a module function, then the first parameter will be whatever data structure or thing is referred to by the module (of course Elixir is not perfect). This was a major bone of contention with erlang, which, quite frankly is all over the place and there are several erlang functions which I am constantly looking up the docs on and shaking my head.