-
-
Notifications
You must be signed in to change notification settings - Fork 267
using streams2 for db.createReadStream() #176
Conversation
…special case in the tests
…se otherwise (streams2ism)
Here's the benchmark results from running BEFORE (current master, 75104e0):
AFTER (this patch, bc791ba):
That's a 17% speedup from the old code to this streams2 patch. Hooray! |
This is super good. Definitely 👍 |
why does close happen before end? |
@dominictarr That is a streams2ism. It will happen at some point before end, caused by internal buffering. |
@@ -3,12 +3,10 @@ | |||
* MIT +no-false-attribs License <https://github.com/rvagg/node-levelup/blob/master/LICENSE> | |||
*/ | |||
|
|||
var Stream = require('stream').Stream | |||
, bufferStream = require('simple-bufferstream') | |||
var Readable = require('readable-stream').Readable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readable-stream
doesn't check to see if you have Readable from core (node 0.9+) -- it was recently updated to be the same as 0.10.15, but it doesn't stay version-locked. You probably want to check for core support first.
I.e.
var Readable = require('stream').Readable || require('readable-stream').Readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -44,6 +36,10 @@ function ReadStream (options, db, iteratorFactory) { | |||
this._keyEncoding = options.keyEncoding || options.encoding | |||
this._valueEncoding = options.valueEncoding || options.encoding | |||
|
|||
// backwards compatibility for the test suite: | |||
this.readable = true | |||
this.writable = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these can go, as can the test case cruft for them
LGTM The changes to the test cases around close/end are slightly concerning and I don't fully understand what's going on there, however, I'm pretty happy that we're pushing responsibility for maintaining state etc. to Anyone else got anything to add on this? Otherwise I guess it can be merged when these minor things are fixed up. @substack are you happy to become one of the maintainers? See the discussions on this when we added our last maintainer, @pgte: #160 (comment) |
and while you're at it, you can remove simple-bufferstream since it's only there to support fstream compatibility in the ReadStream. |
The close/end changes are due to how with streams 2 there is no way of knowing from the producer when a readable stream was done being read because of internal buffering and how with streams 2 you can't I'll become a maintainer, sure! I don't plan on doing anything differently however as I'll still send pull requests. |
@substack so how do you know when the stream has finished, is that the 'finish' event? |
Only the consumer knows when the stream is finished. There is no 'finish' event. |
this looks like an end event to me... |
publishing a @0.15.0 with this and linking to leveldown @0.8.0 (which has the new gt/gte/lt/lte stuff and nan as a dependency). no docs yet for gt/gte/lt/lte but it's there, along with start/end adding @substack as a maintainer, 👏 |
This patch uses readable-stream
.Readable
for thedb.createReadStream()
api to implement the readable half of issue #106. Only a few minor tweaks to the existing test suite were necessary to work around a few streams2isms.This patch also fixes the issue where calling .pause() will let one more element through before pausing and I was running into some issues with piping to multiple destinations that this patch also seems to have fixed.