node.js - child_process stream backpressure -


i'm using exec-stream node.js , piping stream through few other transform streams, through node-brake stream limit data rate. braking stream seems have no effect, , in fact data lost @ end of long chain.

execstream('some-external-binary').pipe(transform1).pipe(transform2).pipe(brake(1024)) 

what think happening child_process stdout stream (within exec-stream) not pausing, , therefore buffers fill until data lost.

do child_process streams behave way? there way backpressure work child_process streams?

i'm not familiar enough exec-stream , node-brake understand avenues data-loss.

however, did little experiment see if node-brake has back-pressure effect, mentioned potential area data-loss.

file hosted on gist.

### created http://stackoverflow.com/questions/34982953/child-process-stream-backpressure please pardon coffeescript, couldn't stand extend stream.transform in native javascript. ### fs = require("fs") execstream = require("exec-stream") brake = require("brake")  file = fs.createwritestream("tmp.txt")  class double extends require("stream").transform   _transform: (chunk, enc, cb) ->     @_last ?= date.now()     @_called ?= []     @_called.push date.now() - @_last     @_last = date.now()     @push chunk.tostring() + chunk.tostring()     cb()  class uppercase extends require("stream").transform   _transform: (chunk, enc, cb) ->     @push chunk.tostring().touppercase()     cb()  sum = (nums) ->   o = 0   o += in nums   o  dotest = (size) ->    transform1 = new double()   transform2 = new uppercase()   transform3 = new double()    execstream("dd", ["if=/dev/urandom", "bs=1024", "count=1"])     .pipe(transform1)     .pipe(transform2)     .pipe(brake(size))     .pipe(transform3)     .pipe(file)    file.on "finish", ->     fs.stat "tmp.txt", (err, stats) ->       throw err if err       called1 = transform1._called       averageprebrake = sum(called1) / called1.length       called2 = transform3._called       averagepostbrake = sum(called2) / called2.length       console.log """         generated brake(#{size}): #{stats.size}         average time between transformations pre-brake:  #{averageprebrake}ms         average time between transformations post-brake: #{averagepostbrake}ms       """  dotest 1024 dotest 256 

results of process below.

stdout above coffeescript

i notice there no gaps between transformations before brake. however, brake disrupts transformations later down line. given data, suspect node-brake has no back-pressure effect.

[screenshot of console output generated sh2png utility]


Comments