Erlang to external app interfaces

Raimo Niskanen raimo@REDACTED
Mon Feb 4 14:31:37 CET 2002


You seem to have got the grip of the subject already, so I have just
some comments.

Regular ports use pipes for inter process communication, so there is not
really any network communication since the processes involved must be on
the same host.

The overhead for linked-in drivers occurs in at least 3 different
contexts:
1. Linking in the driver.
2. Opening the port.
2. Sending to the port / receiving from the port.

Linking in the driver is probably done once, so it is often not
critical.

Opening the port consists of allocating the port structure, initializing
all fields, and calling the driver->open() function, which takes the
time it needs.

Overhead in sending to the port consists of calling the erlang:'!'/2
BIF, looking up the port, analysing the mode and validity of the port,
and, depending on the mode perhaps flattening and copying the send data.
So if you want to minimize this overhead you should send the data as one
or a few binaries - then the data will not be copied, just the pointers
to the data. Finally, the driver->outputv() function is called.

Overhead when calling a BIF is roughly looking up the BIF in the modules
export table (array lookup), pushing live data on the stack (emulator
stack, not processor stack). When writing a BIF there are _lots_ of
rules to follow regarding memory allocation, result data construction,
and so on to follow, and the rules might change in the next Erlang
release. This is _really_ deep water.

The only way to get less overhead than calling a BIF is to add a new
instruction to the Emulator loop, and now we get into deep sea diving.
Not recommended at all. The probability for mistakes is approaching one.



Do some measurements, and/or explain more about your application.

/ Raimo Niskanen, Erlang/OTP, Ericsson UAB



Chris Osgood wrote:
> 
> I know there are a few different ways to hook Erlang to non-Erlang
> applications.  I'm curious about the performance of each.
> 
> The regular ports stuff seems kinda slow since it uses a regular network
> connection.  This method is "clean" though.
> 
> Then you have linked-in drivers.  This seems faster than regular ports,
> but how fast is it?  As fast as a BIF, or is there some "port" overhead?
>  This method is mostly clean.
> 
> And finally, you have BIF's.  It was very easy to add my own BIF's to
> Erlang, and I assume these are pretty fast.  In fact, for an Erlang
> newbie like me, it was easier than doing a linked-in driver.  This
> method is not as clean as using ports because you are changing the
> Erlang core.
> 
> Am I missing another technique?  Is there another way besides the BIF's
> to link right into the Erlang core for maximum performance? Are
> linked-in drivers just as fast?
> 
> Which is _the_ fastest method?  I need not only fast function calls, but
> lots of bandwidth for passing data too.
> 
> Thanks!
> 
> --
> // Chris



More information about the erlang-questions mailing list