17.01.2015 Views

Erlang and OTP in Action.pdf - Synrc

Erlang and OTP in Action.pdf - Synrc

Erlang and OTP in Action.pdf - Synrc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

288<br />

12<br />

Drivers <strong>and</strong> Multi-Language<br />

Interfaces<br />

At this po<strong>in</strong>t we have a really nice implementation of the cache. It already does a<br />

number if <strong>in</strong>terest<strong>in</strong>g th<strong>in</strong>gs; th<strong>in</strong>gs like provide a persistent store, distributes the cached<br />

objects, h<strong>and</strong>les session objects, etc. Over all the Erlware guys are very happy. However,<br />

there is one small problem. Several of the objects that are cached are gett<strong>in</strong>g quite large.<br />

That’s mak<strong>in</strong>g those objects a bit slow to distribute <strong>and</strong> they are tak<strong>in</strong>g up a lot of memory.<br />

After a short analysis it looks like these large chunks of data are pretty compressible. So<br />

Erlware guys put out a requirement that the cache support some type of compression. That’s<br />

generally not a problem, however, there aren’t really any good compression libraries <strong>in</strong><br />

<strong>Erlang</strong>. There are a several very good compression libraries out there of course, but they are<br />

written <strong>in</strong> C though. it seems prudent to take one of those libraries <strong>and</strong> wrap it for use <strong>in</strong><br />

<strong>Erlang</strong> rather than try to implement a compression scheme from scratch <strong>in</strong> <strong>Erlang</strong>. This<br />

approach also gives us the opportunity to <strong>in</strong>troduce you to <strong>Erlang</strong>’s specialized foreign<br />

function <strong>in</strong>terface.<br />

I said <strong>Erlang</strong>’s ‘specialized’ foreign function <strong>in</strong>terface for a reason. At the highest level <strong>Erlang</strong><br />

is no different from any other language; it allows you to make use of libraries <strong>and</strong> code<br />

written <strong>in</strong> other languages. However, as you dig deeper it becomes apparent that <strong>Erlang</strong> is<br />

actually very different. Most other languages have a foreign function <strong>in</strong>terface to C. Where<br />

the languages provides some way to compile or l<strong>in</strong>ks <strong>in</strong> C code that the language may, then<br />

call <strong>in</strong>to. <strong>Erlang</strong> does it differently; it extends the message pass<strong>in</strong>g paradigm to <strong>in</strong>teract<strong>in</strong>g<br />

with foreign code as well. All of <strong>Erlang</strong>’s foreign <strong>in</strong>terface approaches rely on pass<strong>in</strong>g<br />

messages back <strong>and</strong> forth between the foreign code <strong>and</strong> the <strong>Erlang</strong> system. The method of<br />

©Mann<strong>in</strong>g Publications Co. Please post comments or corrections to the Author Onl<strong>in</strong>e forum:<br />

http://www.mann<strong>in</strong>g-s<strong>and</strong>box.com/forum.jspaforumID=454

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!