demorgan

demorgan

Fetching tens of thousands of files regularly

Long time lurker here :wave:

Some background: I’ve been learning and playing with Elixir for about a year now. I did a few simpler projects with Phoenix, but now I wish to try something a bit harder.

As the title suggests one of the parts of the system I’m trying to build is going to fetch thousands of files regularly, perform some form of processing and then save any relevant information.

I think I have most of the parts figured out. There are plenty of good resources of doing APIs + DB and making that handle lots of requests from the outside.

What is the best way to handle this tho when the application itself generates that amount of work? For doing the processing I’m looking at Rust NIF, which looks promising & I’m curious to play around with it. My question is more around how to handle the logic around a large (and let’s imagine increasing) volume of work. I’ve looked at GenStage, but I’m not sure I understand enough to imagine how it would work. What would be the tradeoffs in Elixir between getting the work done fast making sure the app doesn’t crash itself.

Another thing I’m trying to wrap my head around is: How to write this without limiting the application in the way that it’s written. If a worker pool is used that might work, but what if the app is hosted on GCP or AWS and the machine can be scaled vertically, the app wouldn’t scale without changing the code?

How can I exploit the concurrency here optimally? How does one determine the boundaries in such cases and then make sure they are respected?

I’m not sure I’m explaining well enough here, that’s probably due to my level of understanding =)

Most Liked

dimitarvp

dimitarvp

General advice: stay away from NIFs for as long as humanly possible.

Even if your processing code ends up being slow and inefficient, stick with it for a while. Don’t introduce much more complexity until you’ve shaped a working solution.

I’d recommend GenStage and Broadway generally but in order to stick to simplicity I’d much more readily recommend you just look at the docs of Task.async_stream (3-args and 5-args).

lpil

lpil

Creator of Gleam

That sounds like not much data in an hour! Perhaps try the simplest and easiest implementation and see how that works. Best not to over engineer when it might not be required.

dimitarvp

dimitarvp

Erlang’s crypto package is a very good start.

Summoning @voltone for additional options, if he doesn’t mind.

lpil

lpil

Creator of Gleam

A few questions: How regulary are they fetched? How large are the files? Where are they fetched from? How long does it take to process one of these files? :slight_smile:

If we know more about the problem it’ll be easier to make recommendations

al2o3cr

al2o3cr

+1 to the recommendation for Oban.

Re: the NIF angle, also consider if ports would be a good fit. You could write a separate Rust program that talks over a port and does the crunching. There’s some overhead - since data is being transferred between operating-system processes - but OTOH if the program on the other end of the port fails it doesn’t affect the BEAM. The NIF approach isn’t free of performance issues related to serialization either.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
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
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
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
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
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
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
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement