OrontaMedu
Long running tasks and external processes: in Elixir or Rust?
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)?
Most Liked
derek-zhou
Much have been said about you should stick with a pure Elixir approach, then only move on to Rust NIF when there is significant benefit in doing so. I want to point out the CGI style System.cmd interface is most likely not what you want, should you decide that neither pure Elixir nor Rust NIF is good enough for you.
If you must use an external process, then the only valid reason is that you need to keep significant state in that external process. The best way to communicate with a stateful external process is via a port. Rust offers an excellent async library, Tokio, to make that happen. You would need to write a couple hundred lines of Rust code to wrap the Rust library though.
D4no0
Are you willing to sacrifice all the benefits of elixir for some performance? If yes then go with 2.
LostKobrakai
Yes. With external programs you have to marshall communication in both directions. Staying with elixir means you don’t need to do that.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









