Saturday, February 16, 2008
Interfacing Erlang with C - explained by Joel Reymont
Great tutorial on how speeding up Erlang with linkedin C code. But hopefully you won't have to do it because it makes your software hard to maintain and the C part might crash your program. But if you have to interface with C, then first check whether a C-node (as for example done in ErlyCairo) has enough performance, a C-node uses it's own memory space and doesn't crash your Erlang program, in case things go wrong. But if your C code is very robust, and you really need the performance, Joel's tutorial is a great introduction to that topic.
Subscribe to:
Post Comments (Atom)
2 comments:
I've been reading the relevant chapter from Armstrong's book and it seems to me like all foreign function calls are handled in a serial fashion by the Erlang connected process (the process which is linked to the Port). If there are 2 Erlang processes which are trying to invoke an external C function, then the function calls happen one after the other and not simultaneously. Correct me if I'm wrong here.
Is there a way to parallelize these calls? One way I can think of is to open several ports. But is that an efficient way to do this?
You are mostly correct, just the Erlang VM does its own thing to keep running these linked-in drivers as smooth as possible (special "real" threads, if I remember properly).
One project I am aware of has lots of background information about linked-in drivers efficiency in their README and might help to clarify your questions:
http://www.snookles.com/erlang/edtk/edtk-1.5.1.README-cnewcom
Post a Comment