50 likes | 207 Views
Yet Another Tokyo Cabinet – Erlang binding. Overview. Tokyo Cabinet Ultra-fast key-value data store Erlang Ultra-robust framework implementation for distributed systems Erlang interface for Tokyo Cabinet Standard binding interface is defined in tokyocabinet /tokyocabinet.idl
E N D
Overview • Tokyo Cabinet • Ultra-fast key-value data store • Erlang • Ultra-robust framework implementation for distributed systems • Erlang interface for Tokyo Cabinet • Standard binding interface is defined in tokyocabinet/tokyocabinet.idl • Simple architecture • Related works • tcerl – good TC-erlang binding, with dets/ets/mnesia compatible interface
Standard ErlangLinkedinDriver • Erlang code calls C code. • C code calls Erlang code. • Former. • Pros: high-thruput • Cons: higher-latency, C-module said to be bottleneck Call by message (using erlang:send/2), different thread context. Erlang code Returen by message (using receive),different thread context. C module
Alternative ErlangLinkedinDriver • Using erlang:port_control/2 • (not send/2, port_command/2) • Pros: low-latency (expected) • Cons: lower-thruput(in fact, not so good) Call by function call (pushing onto stack), in same thread context. Erlang code Return by popping from stack. C module
Alternative ErlangLinkedinDriver • int control(ErlDrvDatadrv_data, unsigned int command, char *buf, intlen, char **rbuf, intrlen) • This is a special routine invoked with the erlang function port_control/3. It works a little like an "ioctl" for erlang drivers. The data given to port_control/3 arrives in buf and len. The driver may send data back, using *rbuf and rlen. • This is the fastest way of calling a driver and get a response. It won't make any context switch in the erlang emulator, and requires no message passing. It is suitable for calling C function to get faster execution, when erlang is too slow. • If the driver wants to return data, it should return it in rbuf. When control is called, *rbuf points to a default buffer of rlen bytes, which can be used to return data. Data is returned different depending on the port control flags (those that are set with set_port_control_flags). • http://erlang.org/doc/man/driver_entry.html