Uh oh!
There was an error while loading. Please reload this page.
streams: add cork option to pipe - #2020
Conversation
chrisdickinson
commented
Jun 19, 2015
Curious: why not just call |
trevnorris
commented
Jun 19, 2015
cork knows about the high water mark? There's something I must be misunderstanding. |
There was a problem hiding this comment.
there should probably be a comma after Before each write
calvinmetcalf
commented
Jun 19, 2015
@chrisdickinson because then you have to wait until you hit the highwatermark before you actually write anything, see the comment by@indutny in the readable stream issue |
There was a problem hiding this comment.
I wonder if pulling this anonymous function out of maybeCork() would help performance-wise?
chrisdickinson
commented
Jun 19, 2015
OK, I was wrong – cork and uncork have no idea about highwatermark. That said, I'm not sure I'm fully on board with this change (though I may be misunderstanding it.) So, to check my assumptions about how streams work (and in particular, how net.Streams work):
Right now streams will be flushing chunks without using |
Adds an option to .pipe to cork it before each write and then uncork it next tick, based on discussion at nodejs/readable-stream#145
chrisdickinson
commented
Jun 19, 2015
Things that could cause my assumptions to be incorrect:
These both seem like TCP-specific concerns – it might be better to solve them at the |
calvinmetcalf
commented
Jun 19, 2015
This is the more general benefit that could apply to other streams that want to strike a balance between per write overhead and latency |
trevnorris
commented
Jun 19, 2015
Just for reference, this is basically the same thing the http module does today. |
trevnorris
commented
Jun 19, 2015
Another key component in this is the interaction with uv_try_write. You want to immediately write out as much as the kernel can handle then queue the remaining. It's not uncommon that all writes can be done immediately. This affects all uv_stream_t instances. |
calvinmetcalf
commented
Jun 19, 2015
@mscdex updated based on your suggestions |
indutny
commented
Jun 19, 2015
@trevnorris still it is faster to do just one |
trevnorris
commented
Jun 19, 2015
@indutny internally doesn't it automatically write out as much as possible using uv_try_write before setting up the WriteReq? |
indutny
commented
Jun 19, 2015
Yes, but it will pass multiple buffers as a single input with writev. |
trevnorris
commented
Jun 19, 2015
Sure, but uv_try_write only takes one at a time. That's what I was trying to get at above. Thought it may be a performance advantage to write immediately until uv_try_write fails, then queue up the remaining for writev. Simply because between the first set of running uv_try_write the kernel may have flushed some of the data and could accept more when writev ran. But the timing could also be so minimal that it doesn't really matter. |
indutny
commented
Jun 19, 2015
Not really, it takes multiple: UV_EXTERNintuv_try_write(uv_stream_t*handle,
constuv_buf_tbufs[],
unsigned intnbufs); |
indutny
commented
Jun 19, 2015
Though, your comments are quite correct. I am not suggesting this should be a default behavior in any way. But for my use case it would be beneficial to introduce this option, otherwise I will need to concatenate the buffers manually in memory. |
trevnorris
commented
Jun 19, 2015
Doh. Memory failure. Thanks for correcting me. My comment was more just an observation I realized while looking over this PR. Definitely not something I think should be introduced in this PR. :-) |
chrisdickinson
commented
Jun 20, 2015
We're talking about bringing back Based on this comment, it seems like you should be seeing at least one writev of size N>1. Is the problem that:
|
indutny
commented
Jun 21, 2015
@chrisdickinson they can't happen because I am piping to the socket, not writing to it myself. So every write results in separate |
ronkorving
commented
Jul 11, 2015
I have a use-case where I'm piping from a _transform to a writable, and would benefit from the same solution. For me however, nextTick would be overkill (not sure what the cost of a nexttick is tbh), as _transform already uses a callback to denote the end of a batch of writes. Perhaps the transform use case could be optimized? |
There was a problem hiding this comment.
Not technically correct in the case of autoCork being false.
There was a problem hiding this comment.
True should be more like, 'no need to cork'
ronkorving
commented
Jul 12, 2015
I just submitted #2167 which I think might really benefit from this. |
There was a problem hiding this comment.
Is there a time when dest.cork isn't a function? Won't it error anyways if it isn't a writable stream?
There was a problem hiding this comment.
Ah, that makes sense! Thanks!
jasnell
commented
Nov 16, 2015
@calvinmetcalf ... ping ... is this still something you'd like to pursue? |
calvinmetcalf
commented
Nov 16, 2015
sure I can rebase |
calvinmetcalf
commented
Mar 4, 2016
closing this as I'm not so sure we need this |
Adds an option to .pipe to cork it before each write and
then uncork it next tick, based on discussion at
nodejs/readable-stream#145