[erlang-questions] "sendfile" call as NIF. Good or bad idea?

Steve Vinoski <>
Sat Nov 27 18:53:57 CET 2010


On Sat, Nov 27, 2010 at 6:30 AM, zabrane Mikael <> wrote:
> Hi guys,
>
> There exists a "sendfile" linked-in driver extracted (Tuncer Ayaz)
> from "yaws" (Steve Vinoski) at:
> https://github.com/tuncer/sendfile
>
> The code is a bit cryptic to me (no offense) and I was wondering if
> it's good (or not) to re-implement it as a NIF?
> I'm asking that question after seeing Joel experiment on CouchDB speedup:
> http://www.trapexit.org/forum/viewtopic.php?p=62191&sid=67e9d1167a4d0d6c1fb6f9f4b81ff92b

Not sure why you find it cryptic, since as drivers go it's pretty
simple. Can you provide further details?

The benefit of a driver is that we can just register each socket FD
with erts and it lets us know when each socket is writeable. The
driver mainly just handles tracking how much was written by each
sendfile call, incrementing offsets, etc.

If you implemented it as a NIF, you'd need to perform your own polling
on the socket FDs to know when sendfile can write to them. This alone
might mean a portability issue, since you'd have to know to use the
right polling mechanism for the given platform. You'd also need to do
all this in your own thread, whereas the driver doesn't have to deal
with threads.

--steve


More information about the erlang-questions mailing list