akka/akka — pull request #1061 by jrudolph (2013-01-24 14:57:39+00:00)
Title: introduce WriteFile to send a file to the network without having to read it into a userland buffer, see #2896

Here's a proposal how zero-copy file sending could be handled.

Notes / open questions:

- How to address a file? `WriteFile` currently uses the file path. This could be a possible security leak when something manages to send a message to the connection actor (of course there are all kinds of security leaks if something manages to send messages around but this seems particularly easy). Before `WriteFile` just had a `FileChannel` parameter which, of course, isn't serializable. The question is if you should be able to use `WriteFile` if you aren't on the local machine.
- A problem is that `FileChannel.transferTo` (or linux `sendfile`) may block on file IO when the network is faster than the disk. I'm currently using a single pinned dispatcher to schedule all of the IO operations on. It would probably make sense to have more than one thread executing file IO or in the best case a number IO threads per disk which isn't easy to achieve.

As an aside: Getting around synchronous disk IO on Linux seems to be quite hard. The support in the kernel for asynchronous disk IO on Linux is still lacking. The biggest problem probably seems to be that aio only works on files opened with O_DIRECT circumventing buffering (e.g. see http://www.lighttpd.net/2007/2/11/buffered-io-performance/).