fchabouis

fchabouis

Good solution to launch asynchronous tasks with rate limiting

Hello,
This is my first question here, please let me know if it can be improved.

Every night, I would like my server to run a validation process on a number of urls. It computes some hash, download some data, validate it, etc.

It looks like tasks are best suited for this. I’ve also read that supervised tasks are better than just creating unsupervised tasks, for the clean-up, in case the main process is terminated. Can you confirm that I’m taking a good direction so far ?

Also, my server is running on a small instance, I’m worried that if I give it a big list of tasks, it will just crash because of the small resources I have available. I was hoping that the Task.Supervisor would have an option about the maximum number of concurrent tasks running, but I didn’t see any. Any information about this ?

I saw async_stream had a concurrency limit option, but didn’t understand if it could be helpful for my situation. Is it ? And is it compatible with a Task.Supervisor ?

Probably many newbie questions here, thanks for your time !

Marked As Solved

gregvaughn

gregvaughn

I use Task.Supervisor.async_stream_nolink/6 in several places for this sort of thing. The tasks are supervised by the supervisor in the first param, but they are not linked to the caller. In the caller, I then Enum.reduce over the resulting stream and collect a little “report” of number of successes/errors/etc and log the result.

I typically specify the concurrency and unordered settings in the options. This concurrency throttling mostly helps me to not overwhelm some external API that the tasks call. It’s not because I’m worried about the BEAM handling a large number of tasks.

Also Liked

hauleth

hauleth

Do not worry. BEAM uses preemptive scheduler (at least from the viewpoint of the user) so it should be ok to spawn new process per each URL (depending on the scale) and just let VM do its magic. Erlang processes are quite cheap, so this should not be a problem if there is list of 100s of URLs, I would start thinking about any throttling only if there would be over 1k of such. In that case you can use GenStage which allows for rate limiting.

Where Next?

Popular in Questions Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement