On Saturday, June 27, 2015 at 8:10:37 AM UTC-7, Jason Harrelson wrote:
Gentlemen, thanks for the replies. Both of your suggestions are very good and have shed some light on my understanding. However, I will go a little further into the details of an implementation I am working on so that you have a little better context.
I have a Phoenix web request that will be spawning a process to contact an asynchronous API using 0mq. This process (or group of several processes if necessary) will listen for a web timeout and messages from a 0mq pub/sub socket. When the web timeout is reached, this process will message to the web request process with the results it has already gathered and the web process will return a response and cease to exist. However, the async subscribing process will stick around and continue to listen for more messages until a second timeout is reached. If more messages arrive, it will write this data to the system's DB.
The main concern I have is if the 2nd timeout fails to occur for some reason and this process sticks around forever? I am trying to find an OTP'ish way to monitor this process not for crashes, but for staying alive too long, as you can imagine the system ramifications if this happened repeatedly.
FWIW, I find it very helpful not to call them processes. Call them Eprocs or something else. You are applying intuitions from expensive heavyweight unix processes that simply don't apply to BEAM processes.
If the process is simply waiting on a message, it's going to take almost no resources until that message shows up. You don't want to leak processes if you don't have to, but you can leak processes for much
longer than in the traditional unix fork/exec module.
I found this blog post very helpful in starting to think about the "let it crash" methodology for BEAM processes.
To me it sounds like you are attempting to engineer for flaws in the BEAM VM. Why do you think the process won't
get it's 2nd timeout?
The BEAM VM does a lot to isolate the runtime from the vagaries of unix processes. There are special drivers for
all the I/O functions that engineer around the kind of I/O hangs that you'd have to worry about with normal unix
processes.
I'm not saying things can't go wrong, just that they will go wrong in completely different ways that you are used
to in dealing with either unix processes or threads. BEAM processes are a very different beast and until you've
got actual running code and experience in how that code fails, it's very hard to know in advance what the failure
modes will be. The more you can educate yourself on the Erlang scheduler the better. This blog post covers the
basic philosophy.
- Booker C. Bense