Put FD's on sockets, or remove fs.sendfile #3854
Comments
fs.sendfile() needs to be replaced by something better. What we need is a smarter approach for sending data from one stream to another. |
I agree, of course, and it should probably be added as an implementation detail in the But in the meantime, why even have fs.sendfile, if you can't actually do anything with it? Maybe we could let it take a libuv handle instead of a socket fd? |
Reasonable but not trivial to implement unless you resort to platform-specific #ifdef hackery. uv_fs_sendfile() takes an int so you'd have to extract the relevant fd from the libuv handle on Unices. Not pretty but possible and reasonably straightforward. It gets gnarlier on Windows - uv-win handles aren't backed by file descriptors. As a stop-gap measure we could implement the above and say it's broken on Windows. |
Is |
@piscisaureus You should chime in here as well. |
@bnoordhuis Tomorrow :-) |
We could make it work on all platforms (it's not even very difficult), but it's pointless. Using sendfile() has virtually no benefits in the current setup. |
Okay, so let's remove it? |
drop it! |
@piscisaureus It has virtually no benefits on Windows, but on Unix, it prevents a copy out of kernel space, doesn't it? Of course, fs.sendfile it hasn't really ever worked properly without ridiculous hoop-jumping, and has been completely broken for two stable branches now, and life seems to be going on. I'd be ok with challenging any feature-requesters to provide some benchmarks to justify the performance benefits. |
@isaacs On windows you can easily implement sendfile using the TransmitFile api. The problem however is that you have to block the thread pool until the file has been written, or go back to the thread pool often. We need a good story for this - but naive sendfile isn't that. |
Winsock TransmitFile reference: http://msdn.microsoft.com/en-us/library/windows/desktop/ms740565.aspx |
Ok, no one is using this, and making it work will require a rewrite. Let's remove it for 0.10. |
Axed in 910e24b. |
FWIW I ran across this: https://www.myricom.com/software/myri10ge/440-why-don-t-you-report-tcp-sendfile-performance-for-macosx-on-your-myri10ge-performance-webpage.html
|
it also looks like sendfile() could be tweaked using TCP_CORK for network transfers, to get the best out of it. See: http://baus.net/on-tcp_cork |
sendfile(2) can only send data from a file fd to a socket fd.
However, since we don't expose the fd on socket handles, so having fs.sendfile is confusing and worthless.
The text was updated successfully, but these errors were encountered: