-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Duplex stream support for separate readableHighWaterMark and writableHighWaterMark #14555
Comments
@guymguym could you describe a bit why it may be desirable to have these separately? cc @nodejs/streams |
I’m actually a bit surprised this didn’t already exist, so 👍 from me. Also, just for clarity, this should be implemented on the @Fishrock123 One problem I could imagine is that high/low water marks can’t really ever have an identical and meaningful value if one side is in object mode and the other isn’t. |
@Fishrock123 this occurs anytime you mix between object modes on the same transform stream, in that case the highWaterMark units is not suitable to measure the buffer size for one of the modes. Here's an example to illustrate the issue:
|
@addaleax You are right of course, this behavior is inherited from However it makes less sense for Duplex streams compared to Transform, so I just chose to describe it from the usage point of view rather from the impl pov. This is currently implemented inside the ReadableState and WritableState ctors: |
When I think about it, this is also relevant for transform streams of the same objectMode, as the input and output might still have different proportions. For example think of a transformer that pushes two lines for every input line... |
I'm definitely 👍 on this. Would you like to assemble a PR? |
sure. will do. |
PR is up. It's my first PR for nodejs so let me know if I missed any guidelines, or you prefer different code for any reason, and I would be happy to make changes. |
This commits adds support for readableHighWaterMark and writableHighWaterMark in Duplex stream, so that they can be set without accessing the internal state. Fixes: #14555 PR-URL: #14636 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
This need comes from the practice to use transform streams to perform pipeline processing with backpressure, in order to process incoming binary data, by splitting it to intermediate chunk objects. In such cases the transform stream will accept buffers as input (
readableObjectMode: true
) and push out objects (writableObjectMode: true
), or vice versa.While the objectMode flag supports separation between readable and writable, the highWaterMark option is unified between the stream roles, which doesn't allow to set the internal buffer size units with respect to the stream type. It seems that optional support for
readableHighWaterMark
andwritableHighWaterMark
is a natural complementary option to the separatedreadableObjectMode
andwritableObjectMode
options.If PR's are welcome I can code the same handling for in the ctors of
Readable
andWritable
and add to docs.LMK what you think,
Thanks!
References:
• https://nodejs.org/en/docs/guides/backpressuring-in-streams/
• https://github.com/nodejs/node/blob/master/lib/_stream_readable.js#L69
The text was updated successfully, but these errors were encountered: