Skip to content
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

Feature/163 global download upload limit #1040

Open
wants to merge 5 commits into
base: master
from

Conversation

@chtrinh
Copy link

chtrinh commented Feb 11, 2017

throttleDownload() and throttleUpload() helper methods for rate adjustments

#163

chtrinh added 3 commits Feb 11, 2017
throttleDownload() and throttleUpload() helper methods for rate
adjustments
@BenmasterTM

This comment has been minimized.

Copy link

BenmasterTM commented May 15, 2017

HI, I try this changes in the webtorrent client in the webtorrent-desktop client, and when I try to set the upload/download limit for Web Torrent, this changes dont work, the only way I found to slowdown the upload files from the webtorrent client in webtorrent-desktop is changing the webtorrent/node_modules/bittorrent-protocol/index.js changing the Wire.prototype.piece function, and encapsulating the code into a timeout:

 var self = this;
(function(self, index, offset, buffer) {
setTimeout(function() {
self._debug('piece index=%d offset=%d', index, offset)
self.uploaded += buffer.length
self.uploadSpeed(buffer.length)
self.emit('upload', buffer.length)
self._message(7, [index, offset], buffer)
}, 800)    
})(self, index, offset, buffer)

altering the timeout time change the upload speed to the web seeds, but cause many messages "start backpressure" from the simple-peer module, I know is not a fix, is only a test, but i think to limit the web seed upload/download speed is complicated due the bittorrent protocol itself... i dont know if is better/possible encapsulate the webtorrent client into some other throttle component.

@chtrinh

This comment has been minimized.

Copy link
Author

chtrinh commented May 16, 2017

How did you set upload/download limits for webtorrent-desktop client?
it should be something like this:

var torrent = new WebTorrent({downloadLimit: 10240, uploadLimit: 10240}); // (downstream/upsttream) bandwidth to 10 KB/s

This PR relies on https://www.npmjs.com/package/stream-throttle to throttle your bandwidth.
I believe this is using leaky bucket algorithm to perform rate limiting.

@BenmasterTM

This comment has been minimized.

Copy link

BenmasterTM commented May 16, 2017

Yes I try that:

let client = window.client = new WebTorrent({downloadLimit: 10240, uploadLimit: 10240})

but the clients connected to the webtorrent client get 100% of my internet connection, i think is because im talking always about WebRTC clients (I dont test with regular uTPC clients, but in the code I see self.type === 'tcpOutgoing' and i think the web clients go for another point)

Edit: I test the if

  if (self.type === 'tcpOutgoing') {
    self.setThrottlePipes()
    console.log('LIMITED SPEED')
  } else {
    conn.pipe(wire).pipe(conn)
    console.log('NOOPE')
  }

And in my log appear only 2 "NOOPE"

EDIT 2: I test to remove the if and let only the self.setThrottlePipes() line.. and works, the WebPeer upload are locked to 10Kb/s... why this IF is here??

@chtrinh

This comment has been minimized.

Copy link
Author

chtrinh commented May 17, 2017

My initial use case was for TCP not WebRTC. IIRC, I encountered an edge case where you couldn't always set throttle pipes. You don't know what "tcpIncoming" are going to be use for.
https://github.com/chtrinh/webtorrent/blob/462a1916fc1736fa9ede2ce0240e1500efad51de/lib/peer.js#L32-L39

I would try something like so:

 if ((self.type === 'tcpOutgoing') || (self.type === 'webrtc')) {
    self.setThrottlePipes()
 } else {
    conn.pipe(wire).pipe(conn)
  }

HTH

@BenmasterTM

This comment has been minimized.

Copy link

BenmasterTM commented May 17, 2017

The correct value in Web Peers is self.type === 'webrtc', but works correctly, thanks!

Copy link

TwoAbove left a comment

Looks good!

But where are the tests for the new features?

I think it's a really good idea to add them

@BenmasterTM

This comment has been minimized.

Copy link

BenmasterTM commented Jun 25, 2017

Hi, I found an error in specific case: If you change the upload or download speed while torrents are downloading/uploading, (with the helper function or directly in webtorrent.uploadSpeed / webtorrent.downloadSpeed), the webtorrent process crash:

Error: Uncaught, unspecified "error" event. (Requested tokens 2984254 exceeds bucket size 1049600)
    at Throttle.emit (events.js:163)
    at Throttle.onerror (D:\Escritorio\electro\node_modules\webtorrent\node_modules\readable-stream\lib\_stream_readable.js:562)
    at emitOne (events.js:96)
    at Throttle.emit (events.js:188)
    at onwriteError (_stream_writable.js:344)
    at onwrite (_stream_writable.js:362)
    at afterTransform (_stream_transform.js:79)
    at TransformState.afterTransform (_stream_transform.js:54)
    at D:\Escritorio\electro\node_modules\webtorrent\node_modules\stream-throttle\src\throttle.js:34
    at _combinedTickCallback (internal/process/next_tick.js:67)
    at process._tickCallback (internal/process/next_tick.js:98)
@rigelk

This comment has been minimized.

Copy link

rigelk commented Dec 15, 2017

@chtrinh do you still plan on finishing this ?

@quicoto

This comment has been minimized.

Copy link

quicoto commented Mar 18, 2018

Any updates on this? 🙏

@BenmasterTM

This comment has been minimized.

Copy link

BenmasterTM commented May 6, 2018

Have webtorrent added some similar functionality, or we need to keep this "fix" added?
In my case I need limit download/upload speeds but I see no oficial support in the main branch.

@TwoAbove

This comment has been minimized.

Copy link

TwoAbove commented May 6, 2018

@BenmasterTM unfortunately, no news on that, but I can confirm that this fork works

@stale

This comment has been minimized.

Copy link

stale bot commented Aug 4, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Aug 4, 2018
@stale stale bot closed this Aug 11, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Nov 9, 2018
@webtorrent webtorrent unlocked this conversation Aug 9, 2019
@feross feross reopened this Aug 9, 2019
@stale stale bot removed the stale label Aug 9, 2019
@feross feross added the enhancement label Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.