Skip to content

RFC - Provide true node streams #776

Closed

Description

@dhensby

After investigating the pause / resume functionality for our existing Request objects, I looked into what it would take to turn them into bonafide streams instead of a semi-ducktyped stream.

Current issues

At the moment the Request class is quite complicated and has sprinklings of if (this.stream) throughout and I feel we could greatly simplify the core logic by moving to a "stream first" implementation where Requests could be promisified on demand.

The Requests from tedious are essentially streams, so this would allow us to interface with them in a more straightforward fashion.

The current stream implementation we have doesn't work particularly well if you also want to make use of the promise functionality, so we need to clear up that usage a bit more too.

Changes required

  • Request object extends stream.Readable
  • Stream operates in object mode
  • Add promise transformation method to Request

Impact

  • Deprecation of row event and replaced with data event (generally conform to the Stream interface)
  • Requests will not be promises by default

Challenges

  • Error handling
  • msnodesqlv8 doesn't support resume/pause of requests

Activity

  1. dhensby commented on Jan 4, 2019

    @dhensby
    CollaboratorAuthor

    I guess my initial questions are:

    • Is there a tangible benefit to making Requests first class streams?
    • Shouldn't tedious be implementing a first class stream object too?
    • Is a readable stream the right type of stream? Should it be a transform stream with the tedious request as the input stream?
    • Do we want to patch msnodesqlv8 to implement pause/resume or do we want to drop it as a driver?
  2. dhensby commented on Jan 4, 2019

    @dhensby
    CollaboratorAuthor

    Also alternative approach is not to make the request itself a stream but to make the object that the request.query() (and other methods) return a stream if request.stream is set to true...

  3. dhensby commented on Jan 7, 2019

    @dhensby
    CollaboratorAuthor

    Also alternative approach is not to make the request itself a stream but to make the object that the request.query() (and other methods) return a stream if request.stream is set to true...

    I'm starting to think this is a better idea

  4. willmorgan commented on Jan 7, 2019

    @willmorgan
    Collaborator

    Is there a tangible benefit to making Requests first class streams?

    I don't think so, for BC reasons and also because we're supporting two drivers, one of which hasn't got stream support.

    Shouldn't tedious be implementing a first class stream object too?

    Probably...

    Is a readable stream the right type of stream? Should it be a transform stream with the tedious request as the input stream?

    Following on from our discussion, I think a transformable stream makes sense here if we're considering wider use cases.

    Do we want to patch msnodesqlv8 to implement pause/resume or do we want to drop it as a driver?

    My understanding is that we could start to look at dropping it for future releases because Tedious now supports domain logon which is what msnodesql8 was distinct in supporting. @patriksimek might know better though!

  5. dhensby commented on Jan 7, 2019

    @dhensby
    CollaboratorAuthor

    Following on from our discussion, I think a transformable stream makes sense here if we're considering wider use cases.

    We have to provide the transformer if that's the case. Someone else can use our readable stream and implement it in a Transformer Stream to transform it into their own output. My research tells me readable stream is correct

  6. dhensby commented on Jan 7, 2019

    @dhensby
    CollaboratorAuthor

    I've created a POC for stream objects here: master...dhensby:pulls/stream-first

  7. patriksimek commented on Jan 7, 2019

    @patriksimek
    Collaborator

    @willmorgan I believe msnodesqlv8 performed much better since it's a native module. But it may not be true anymore with latest changes to Tedious.

  8. dhensby commented on Mar 12, 2019

    @dhensby
    CollaboratorAuthor

    So this is blocked until TimelordUK/node-sqlserver-v8#89 is resolved OR we just return a stream from results already loaded in memory..

    The latter would allow us to return a true stream but it would mean there was no performance gain for developers using the msnodesqlv8 driver (though it wouldn't be any worse than it is now)

  9. self-assigned this
    on Mar 12, 2019
  10. changed the title [-]RFC - Turn Request objects into first class stream objects[/-] [+]RFC - Provide true node streams[/+] on Mar 22, 2019
  11. jansivans commented on Sep 6, 2019

    @jansivans

    Any progress on this?
    Can't use it as a regular node stream yet (6.0.0-beta.1) even though TimelordUK/node-sqlserver-v8#89 is closed.
    What I mean by "regular" is using ".pipe" and "for await ... of".

  12. dhensby commented on Sep 6, 2019

    @dhensby
    CollaboratorAuthor

    There has been progress to an extent. We don't return a true node stream but we do expose a reliable API that allows you to pause the result stream across the two supported drivers (sqlserver-v8 and tedious).

    It's not going to be in v6 where we actually return a real stream, for now you'll have to wrap our request objects in your own ReadableStream and implement the backpressure logic (pretty simple to do).

    This change to the API would be a bit too sweeping and require too much work to go into v6, especially as we are now in beta

  13. jansivans commented on Sep 6, 2019

    @jansivans

    Can you please add information to the docs that this is not a real stream and it is just some custom "request"?
    Because I thought it is the usual nodejs stream (it actually has the same methods like pause, resume and some events) and have wasted few days debugging my app.

  14. dhensby commented on Sep 6, 2019

    @dhensby
    CollaboratorAuthor

    What part of the library presents itself as a "real" stream but isn't actually? I'm happy to accept docs amendments you think are appropriate

  15. jansivans commented on Sep 6, 2019

    @jansivans

    "Streaming" part of the docs.
    It shows the same methods as usual nodejs stream has.
    It is not stated that this is a "real" stream, however I thought so because functionality is very similar.
    Maybe it is only me, but maybe somebody will think the same way and will try to use it like a regular stream.

  16. jeffbski-rga commented on Jul 29, 2020

    @jeffbski-rga
    Contributor

    I have added a PR that may help with these issues if you are using the pipe method. My PR wraps the original request in a Node.js Readable stream which supports back pressure and pipes that to the the incoming stream. #1078

  17. dhensby commented on Nov 19, 2020

    @dhensby
    CollaboratorAuthor

    this was fixed in #1078

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions