-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
http: sendfile #47970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: sendfile #47970
Conversation
Review requested:
|
5000573
to
8f7883f
Compare
} | ||
|
||
// TODO (perf): Optimize this... | ||
pipeline(fs.createReadStream(path, { fd, start, end, highWaterMark }), callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read buffers through the fs api and write to the response
Is there any similar implementation or which apis to use could you guide? would like to give it a try!
Relevant issue: #41393 - but see the discussion for why it offers only limited returns beyond cutting node's self-imposed red tape. |
Ultimately I'm not opposed but this would need to match all the functionality of https://github.com/pillarjs/send. |
I disagree with this. It just needs to send the body. All the header stuff would be up to the user. |
Then we are not in agreement. Adding this to core without handling of all the headers does not improve the developer experience, as the user would need to do all of that by themselves. |
For me, this is about performance, not functionality. I don't see this as replacing something like I see only the reason to add any other logic besides sending the body because it is unlikely to get a consensus as to what it should do and how. Also, doing it will take extra and unnecessary effort ( |
That being said. If we don't see a path to make this significantly faster in the future, then it's pointless. I would defer to @bnoordhuis @jasnell @addaleax on that point. I hoped it could be possible to move the whole transfer between the file and socket handle into kernel space or something between that and doing it in javascript like we do now. |
It looks like discussions don't link to issues, but this comment seems relevant to this issue. |
Quick recap: openssl can, when the stars align, use zero-copy kTLS on Linux and FreeBSD to send files over TLS. As to @mcollina's objection: node historically and philosophically has been firmly in the "mechanism over policy" camp. It's not necessary to support all the bells and whistles of |
Ack @bnoordhuis. I'm ok with adding this if it provides a significantly improved performance. |
Sending files is a common usage of the http api's. We could make a specialised path for this that is more optimised, e.g. we could totally skip all streams boilerplate and directly read buffers through the fs api and write to the response. Further steps could be to move the whole thing into native land. The recent ioring optimisation in libuv also adds some interesting possibilities.
This currently only contains a stub as a suggestion for anyone that wants to pick it up.