-
-
Notifications
You must be signed in to change notification settings - Fork 978
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
Support backpressure #18
Comments
I think an easy impl would be to poll Something like this: var SimplePeer = function () {
stream.Duplex.call({highWaterMark: 1024 * 1024})
...
var self = this
setInterval(function () {
if (self._datachannel.bufferedAmount || !self._cb) return
var cb = self._cb
self._cb = null
cb()
}, 250)
...
}
SimplePeer.prototype._write = function (data, enc, cb) {
this._datachannel.send(data)
if (!this._datachannel.bufferedAmount) return cb()
this._cb = cb
} It would also be interesting to investigate if there was a hack to detect when |
Using the 1mb watermark and polling every 250ms would support 4mb/s which seems ok for now (we could dynamically adjust the watermark based how quickly the stream drains etc) |
@mafintosh Nice strategy. Just released it as 5.1.0. |
Right now, we just send as fast as possible. We should support backpressure and detect when
bufferedAmount
gets too high and pause for a while.Relevant:
The solution implemented for
simple-peer
can also be used for websocket libraries likewebsocket-stream
, since data channels and websockets have the same API, and thus, the same difficulties detecting when backpressure is needed.cc @mafintosh, @maxogden
The text was updated successfully, but these errors were encountered: