[erlang-questions] "sendfile" call as NIF. Good or bad idea?
Sat Nov 27 18:53:57 CET 2010
On Sat, Nov 27, 2010 at 6:30 AM, zabrane Mikael <zabrane3@REDACTED> wrote:
> Hi guys,
> There exists a "sendfile" linked-in driver extracted (Tuncer Ayaz)
> from "yaws" (Steve Vinoski) at:
> 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:
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
More information about the erlang-questions