[erlang-questions] Erlang beginner questions

Mihai Balea mihai@REDACTED
Wed Apr 13 22:18:47 CEST 2011


On Apr 13, 2011, at 3:14 PM, Mode7James wrote:

> I'm starting to get it now.
> 
> Essentially creating a thin wrapper VM for a linked-in library is pretty
> much the same thing as a port driver, right?  It basically creates a new
> node, so functions are called by passing messages, which then we go back to
> messages vs function calls.  Why re-create the wheel?  Is there a speed
> difference between the two do you think, or should I stick with a port
> driver?
> 
> If my physics node, using a port driver, crashes, is there an automated way
> to bring it back and restart it without manually restarting it?  If not
> through Erlang itself, has anyone developed an underlying C-based
> application that runs as an overall supervisor?  Keeping track of VM's that
> crash, and restarting as necessary?


Not entirely correct.

You have a number of ways to mesh native code with Erlang:

-  Port: runs in a separate system process and communicates with the VM using the process stdin and stdout. If the driver crashes, the VM survives and can restart the port.

- Linked-in driver: runs in the VM's process space. If it crashes, it will bring down the entire VM (but not the machine running the VM)

- Separate node. You can actually write a pseudo-node in a different language. Look at the ei and ei_connect modules. From the point of view of your Erlang VM, this appears as a normal Erlang node that can send and receive messages. Obviously, if your pseudo-node goes down, nothing bad happens to your VM.

- Recent Erlang releases offer a new mechanism called NIF that allows even tighter integration than a linked-in driver. I'm not very familiar with it, but I suppose the same caveats as for linked in drivers apply

With tighter integration comes increased performance, but also increased risk. You would need to do a cost benefit analysis and figure out what would work best for you.

Finally, if you start your VM with the -heart parameter, you'll get an external heart process that monitors your VM and restarts it if it crashes or hangs

Mihai


More information about the erlang-questions mailing list