Repository navigation
Enable pipe to support back pressure and errors - #1078
Conversation
|
I see the tests are failing since you are running build with MS SQL Server 2008 which doesn't support offset and fetch options. Uggh. Why keeping with something so old (12 years)? I'll work on changing the tests so it doesn't need it. I only used that feature to take advantage of an existing set of data and only doing a partial load since I didn't know how fast the machine and network would be. |
|
Maybe I can simply switch it to using |
|
Oh, I see it actually runs with different versions in each test. Interesting. |
|
Weird results in the tests now. node@10 tests pass for both x86 and x64. node 6 & 8 are all failing in the msnodesqlv8 tests with I guess I'll need some help from the maintainers to understand what is going on here. I don't know why resumeQuery would exist for some versions but not all? Are these older msnodesqlv8 objects not having the same interface? |
|
Hi @jeffbski-rga thanks so much for the effort on this including the tests - I've been a bit busy the past few days but will endeavour to have a look at this over the weekend. |
87d020c to
fa40b9e
Compare
dhensby
left a comment
There was a problem hiding this comment.
I've retargeted this PR at the master branch because this is a breaking change so can't go into the v6 release line; it will have to form part of v7.
I'll have a go and getting the test suite to pass
39d3065 to
d7ad689
Compare
|
I'm going to have to close this and open a new PR because AppVeyor can't cope with the branch being changed |
|
Ah - no, I think I just haven't removed v6 and v8 tests on master yet... |
|
In my latest commit, I have added a toReadableStream method which just returns the ReadableStream. |
|
@dhensby Hi, is there any update? Thanks! |
|
@potatozerg it seemed to fall off their radar. I hope they will resume getting it in. In the meantime, I needed it for my project so I have published it to npm as It seems to be working great. I am primarily using the |
|
@jeffbski-rga Thanks a lot! I will give it a try when I finish my current task. |
|
@jeffbski-rga How should I require(import) it? importing mssql doesn't work anymore. I uninstalled the mssql package and installed yours. Thanks. |
|
@potatozerg sorry didn't see the message till now It's just a scoped package so you use the scope in front of the name like so. import SQL from '@jeffbski-rga/mssql'; |
|
@jeffbski-rga Hi Jeff, I have tried it, but it didn't work. I can provide more info once I get to my office. Basically I have tried all kinds of importing formats that might work, but it keeps popping errors. |
|
@jeffbski-rga It actually works! Thanks a lot. But do you know why when I use the toReadableStream() function it just makes my Nodejs backend extremely slow? The original package(mssql) has the same problem too. |
|
@potatozerg I haven't noticed any problems, seems to run pretty well. I'm using from a lambda. If I had to guess maybe something in your stream processing is not quite right?. I'm using the pump npm library to connect up my readable streams with transform and writable streams since it handles a bunch of edge cases with errors and all. If you want to post a gist URL, I can take a look if there is something obvious. Of course if you have the same problem without using toReadableStream then I don't know, it could still be due to the processing you are doing with the data coming back. For instance, if the write stream supports the writev method it will be able to be given an arrary of rows at a time to deal with, otherwise you'll be stuck with dealing with one row at a time which depending on what you are doing with the data could be very inefficient. It is an order of magnitude faster using the writev in an oracle writeStream I wrote versus inserting a row at a time. |
|
@jeffbski-rga Thanks a lot. I will dig into it when I get the chance. I will keep you updated. |
dhensby
left a comment
There was a problem hiding this comment.
OK - I'm happy with this and would like to merge it subject to the changes requested.
Sorry for the delay on this - I've been busy :(
e79e846 to
ec19f59
Compare
|
OK - I've implemented my requested changes and rebased. Unfortunately the v8 sql driver tests are failing, which is a pain. I'm not sure why either so I'll need to get my windows machine out to try and debug it |
|
Well, this is annoying - I've taken a look on my windows machine and I can't pin-point where this error is coming from. When I step through the execution slowly the test actually completes without node crashing (but it does fail with too few rows). What I do notice is that the stream pauses and resumes for every single row, which seems excessive and maybe is the cause of the crash as nodemsqlv8 may have some issues around repeated pause/resumes. Clearly this isn't ideal but as the tedious implementation works we can assume this is more a problem with the driver than our code. I'm tempted to skip the nodemsqlv8 test for this and come back to it later... |
|
@dhensby Just to be clear my implementation only pauses the stream when the backpressure from the transform and writable streams indicates it is necessary. This comes back as a false during the push as shown below (which matches the node.js stream guidance). origRequest.on('row', (row) => {
if (!readableStream.push(row)) {
origRequest.pause()
}
})Now maybe the test is causing this to be false quite often, but we are following the spec here. |
|
Yes, I don't think the implementation is wrong, I'm just saying what my observation is when running through the debugger. I think the best approach for now is to skip the test for the failing driver and get this merged. |
|
I added the ability to optionally pass in stream options for the readable stream that is to be created when using toReadableStream. This allows one to increase the amount of rows that are buffered by passing in options like const readableStream = request.toReadableStream({ highWaterMark: 100 }) |
|
Thanks @jeffbski-rga - I don't want this to sit around any longer so I'm going to skip the msnodesqlv8 tests for now. @TimelordUK do you have any idea what is going on here? Why the tests on the msnodesqlv8 driver might be dying? |
b18c275 to
5479c08
Compare
pipe method should support Node.js stream back pressure so we wrap the original request in a Readable stream and pipe to incoming stream. Errors are forwarded to the stream.
Since the build server is still running SQL Server 2008, it does not support offset and fetch for limiting the query. Apparently it does support `select top 2000 * from ...` so I can use that instead.
Wrap a request object in a Node.js Readable stream which supports back pressure.
```javascript
const { pipeline } = require('stream')
const request = new sql.Request()
const readableStream = request.toReadableStream()
pipeline(readableStream, transformStream, writableStream)
request.query('select * from mytable')
```
No arguments
Allow options to be passed into toReadableStream that will be used when creating the stream.
For instance to increase the highWaterMark, you could:
```js
const { pipeline } = require('stream')
const request = new sql.Request()
const readableStream = request.toReadableStream({highWaterMark: 100})
pipeline(readableStream, transformStream, writableStream)
request.query('select * from mytable')
```
5479c08 to
d4081b7
Compare
|
I've rebased this as we have just merged in a fix for msnodesqlv8 streams (see #1109) which may be playing a role in these failures... 🤞 |
|
OK - so installing v1 of the driver gets the tests green (but I note some unhandled Promise rejections from some of the tests - presumably from the tear down after the test). What this does mean is that the library only currently supports v1 of msnodesqlv8, so we should make that clearer in the docs (or, better, we should upgrade master to work with v2). |
c55f066 to
97e7799
Compare
|
If there is anything I could do to help let me know. |
|
Sorry for the delay @jeffbski-rga and thanks for the patience - work has been all over the place meaning my time on this project has taken a back-seat. So I think we should merge this as is and then try to find time to get v2 support in for msnodesqlv8 |
|
V2 msnodesqlV8 was a significant rework mostly in cpp to allow Linux support. We can now run on many Linux platforms 64 bit as well as windows. Very little in way of our testing had to be changed so I am not sure why it’s broken your side. I can help take a look when you have time there should be little api difference but driver itself needed quite a few changes to compile and work on both targets. |
|
@TimelordUK yeah - it looks like it's almost entirely compatible, but we are seeing a failure on v2 that we don't get on v1 (I think) - I need to double check all this, I'll open a PR soon |
|
Thanks @dhensby and team for getting this in. I will be able to happily retire my fork once it is deployed to npm. |
pipemethod should support Node.js stream back pressure and forward errors to the stream.What this does:
Modify
pipemethod to wrap the original request in a Readable stream and pipe it to the incoming stream. Errors are forwarded to the stream as well.