l'essentiel est invisible pour les yeux

Friday, June 27, 2008

Asynchronous driver in Erlang using driver_async

Erlang provides some mechanism is to communicate other language, this can be used for to reuse module, speed things up (Erlang is ten times as slow as slow than C), to access OS resource and so on. The below mechanism are provided.

Pipe Drivers
The "pipe drivers" enables bi-directional communication. The external process can be implemented in C or any language, and it can use erl_interface and ei library in order to manipulate data of Erlang as ETERM.

Benefit:

  • Frexible, it can use some types data.
  • Any language

Demerit:
  • Communication overhead

Linked-in Drivers
A driver in Erlang is a library written in C/C++, that is linked to the Erlang emulator and called from erlang. A driver can be dynamically loaded, as a shared library (known as a DLL on windows), or statically loaded, linked with the emulator when it is compiled and linked.

Benefit:
* Faster than "Pipe Drivers"

Demerit:
* Not frexible, to pass the complex data between C/C++ and Erlang is difficult. (see also ei)


Asynchonous Linked-in Driver
The "Linked-in Drivers" is faster than "Pipe Drivers", but it can not scale with a lot of process, since it run synchronously. So If you'd like to take advantage of platforms with multiple CPUs, then you must run some Erlang virtual machine since it run on single thread.

It sounds like great!, but we should care the some problems, multi-thread problem and so on.

Resources:

Next, I'll write an entry about how to create asynchronous driver.