Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

http.ServerResponse#writeFile #1802

Closed
networkimprov opened this issue Sep 29, 2011 · 9 comments
Closed

http.ServerResponse#writeFile #1802

networkimprov opened this issue Sep 29, 2011 · 9 comments

Comments

@networkimprov
Copy link

Provide a writeFile(filename, callback) method of http.ServerResponse (and/or net.Socket) which uses sendfile or splice internally. Would run in the thread pool to avoid blocking.

This was discussed last year and Ry concluded it should wait for the writev patch...

https://groups.google.com/group/nodejs-dev/browse_thread/thread/1461c9ea5e90fc4e/d62fc949de7af66e

Edit: should take a 'noCache' argument, which if true calls posix_fadvise() after each sendfile() call:

  posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
@ry
Copy link

ry commented Sep 29, 2011

We're still not in a place where we can do it. Some day...

@mikeal
Copy link

mikeal commented Nov 1, 2011

if this is the API we want we could add this now using a regular file stream and at some point in the future upgrade it to use sendfile().

either way, this won't make 0.6, but we could consider for 0.7.

@networkimprov
Copy link
Author

I feel the point here is to provide an optimized file-sender. fs.createReadStream(...).pipe(response) is pretty concise already :-)

I'm curious as to why one couldn't create a thread-pool routine to invoke sendfile() for a Socket fd today?

@mikeal
Copy link

mikeal commented Nov 1, 2011

@networkimprov because we don't know when the pending data is actually done being written out. So we want to write the HTTP headers and then do a sendfile() but because the pending writes are not blocking and may be pending or buffered the sendfile syscall may skip ahead of the header writes.

@networkimprov
Copy link
Author

Right, so alongside (or inside) the Socket's buffer-queue you'd keep a file-queue (with each item's buffer-queue position), so that the Socket knows when to invoke a thread-pool sendfile.

And that could be generalized to allow other fd-based modules to write to a Node Socket...

@bmisiak
Copy link

bmisiak commented Sep 12, 2012

Hello. What's the status of this a year into the future?

@bnoordhuis
Copy link
Member

Hello. What's the status of this a year into the future?

Pending.

@jasnell
Copy link
Member

jasnell commented May 15, 2015

@joyent/node-coreteam what do we want to do with this one? I agree it will be useful but it's been sitting here forever with no action. Recommend closing. If someone wants this still we can wait for a PR that actually does it.

@jasnell
Copy link
Member

jasnell commented Jun 22, 2015

Not something that will land in v0.10 or v0.12. Marking as deferred and closing. If this is still something someone wants, then an issue should be opened in nodejs/io.js or nodejs/node

@jasnell jasnell closed this as completed Jun 22, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants