Elixir supervise a golang process?

Clarification EDIT: By “GoLang process”, here I am referring to separate x86_64 linux OS process running GoLang code. Sorry for confusion.

I know about NIFs / Ports. If you are claiming they solve my problem, please provide precise details (perhaps link to sample code) on how they solve my problem.

I have the following problem: There is a GoLang process I would like to put into the Erlang OTP supervision tree:

  • Erlang starts the GoLang process
  • if the GoLang process crashes / dies / becomes unresponsive, Erlang gets a notification
  • Erlang supervisor restarts the GoLang process as necessary

From my research, the two ways to do Erlang/Elixir interop is either NIF or Ports. I am not a fan of NIF, as crash in GoLang = crahse Erlang VM. The stdin/stdout message passing of Ports also sounds a bit weird.

I am wondering if there is any other way for Erlang/Elixir to “supervise” a GoLang process.

1 Like

Assuming by process, you mean “separately running runtime”, possibly the exile library is what you are looking for

1 Like

Use ports. There is nothing wrong of passing packets back and forth on stdin/stdout, if you control both sides.

The only downside of using ports is that there is no back pressure, so if the pipe accumulates too much packets the whole system will misbehave. There are some ways to add back pressure to ports, but you should design the system so that the port communication can never be the bottleneck in the first place.

I have a simple example of using a GenServer to communicate with an external process. The elixir side is [GitHub - derek-zhou/tantivy-erl] and the Rust side is here [GitHub - derek-zhou/tantivy-cli].

4 Likes

As derek said, use Ports. Your use case is exactly what they’re for. If you want a pool of them, you can use NimblePool or poolboy.

maybe rambo, muontrap et al are the tools to reach for? see links here https://github.com/jayjun/rambo#comparisons

1 Like