OrontaMedu

OrontaMedu

In a project there’ll be lots of background tasks run by DynamicSupervisor.

Each task will be making network requests to an external service and is expected to run for a few or 10-20 minutes. And a task will need to save a result into a DB.

The way a task makes an network request could be in one of 2 ways:
(1) via an Elixir library – ExternalLib.make_request(a, b, c)
(2) via an non-Elixir library (in Rust): System.cmd("external_utility", [a, b, c])

Note that both (1) and (2) are black-boxes – they may not be modified. They may only be used.

The (2) in this case is more flexible, faster, more properly implemented and generally is preferable – compared to (1).

Question: from the point of view of Elixir, background tasks, ability to run, manage them, get a return result and so on … – could the Elixir library (1) be better still than the non-Elixir one (2)?

Showing Posts 1 to 10

D4no0

D4no0

Are you willing to sacrifice all the benefits of elixir for some performance? If yes then go with 2.

LostKobrakai

LostKobrakai

Yes. With external programs you have to marshall communication in both directions. Staying with elixir means you don’t need to do that.

dimitarvp

dimitarvp

Not sure you can have something be faster when it hits the network. The CPU is just waiting for a response.

And in your case you don’t even have a Rust library to call in-process, you have an external tool.

I’d say stick to Elixir unless the Rust tool is bringing critically important benefits.

jarmo

jarmo

You can use Oban for running background jobs in Elixir. Can’t see any reason why this might be a bad choice.

OrontaMedu

OrontaMedu OP

Which benefits? Why sacrifise in this case?

OrontaMedu

OrontaMedu OP

What’s "Rust library to call in-process, "? Calling Rust via NIF and Rustler?

dimitarvp

dimitarvp

Yes, exactly that.

OrontaMedu

OrontaMedu OP

The job that the exteranl utility in Rust or Elixir library will do is to send several network requests. As well as returning a result to the calling Elixir code which then will be saved into a DB.
There’ll be no computation.

Do you claim implemeting it via NIF and Rustler would still be better than calling it as an utility via System.cmd(...) ?

dimitarvp

dimitarvp

I am prone to being preachy and absolutist sometimes so maybe I am not the best person to give an answer… but I am leaning to “yes”.

To me calling something in-process has less things that can go wrong. Though seriously, tools that are well-behaved are probably just as safe. (“Well-behaved” in this instance means “they respect shell conventions when having to stream data in/out from/to stdin/stdout”).

Of course I’d also seriously consider just doing the whole thing in Elixir if I can get away with it. As mentioned above, disk or network I/O are 1000x more time-expensive compared to CPU-intensive tasks so who cares if your code that will need 350ms to get back an answer from an external server is written in Rust, Go, Haskell or even Ada or Brainfuck?

Even more supporting my conclusion then. I/O-bound tasks can be written in whatever. You don’t need Rust for that; Rust is for when you need every last bit of performance and minimal memory pressure.

OrontaMedu

OrontaMedu OP

Nobody cares. But that’s not the reason of the utility being written in Rust, for it – the external utility in Rust – itself depends on yet other libraries which do exist in Rust and don’t in Elixir. Or at least in Elixir some of them aren’t mature, up to date and maintaned.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews