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

Limit download/upload speeds (throttling) #163

Open
green13 opened this issue Oct 24, 2014 · 26 comments
Open

Limit download/upload speeds (throttling) #163

green13 opened this issue Oct 24, 2014 · 26 comments

Comments

@green13
Copy link

@green13 green13 commented Oct 24, 2014

It would be cool to be able to limit download/upload speeds.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Oct 24, 2014

+1

@Octexor

This comment has been minimized.

Copy link

@Octexor Octexor commented Oct 25, 2014

+1 ;)

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Oct 25, 2014

Agreed – this feature is useful to limit bandwidth consumption so other apps (like web browsers) can continue to function. (Btw, it doesn't make much sense for the browser version of webtorrent).

Though it sounds simple, it's definitely non-trivial to implement. Limiting the speed of a single node.js stream is easy, but making it work across the whole client will take a bit of thinking...

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Nov 4, 2014

Wow, nice! stream-throttle looks perfect, at least for TCP streams. Making this work with other transports (like uTP and WebRTC) will require additional work. But uTP isn't supported yet, and WebRTC throttling can wait. Looking forward to the PR!

How about naming it --download-limit and --upload-limit?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Nov 4, 2014

Btw, in the picture you posted, the aggregate bandwidth was 410 KB/s. We
need to limit across connections.

On Mon Nov 03 2014 at 11:09:51 PM opfl notifications@github.com wrote:

Whoops, I had accidentally deleted the post. OK, sounds good.


Reply to this email directly or view it on GitHub
#163 (comment).

@feross feross added the help wanted label Nov 29, 2014
@alberto-esposito

This comment has been minimized.

Copy link

@alberto-esposito alberto-esposito commented Jan 12, 2015

As a noobish system administrator it feels a bit strange to me to use Javascript to limit bandwidth. Maybe it's just a prejudice, but node doesn't strike me as being a good candidate.

If it's ok to limit the solution to only unix servers, we could use Ip/Nftables and tc. We could open the stream as a child process, and then the linux kernel could keep track of the process, which is very efficient at doing it.

PID=`ps aux |grep inetd |head -n 1 |cut -b 10-14`

First we get the PID of the process

/usr/local/sbin/iptables -A OUTPUT -p TCP -m owner --pid-owner $PID -j ACCEPT

then we could use iptables to mark the packet, then Traffic control could shaper on a per PID basis

http://lartc.org/howto/lartc.qdisc.filters.html

If it's ok I could try to build something concrete

@alberto-esposito

This comment has been minimized.

Copy link

@alberto-esposito alberto-esposito commented Jan 12, 2015

@Svenskunganka the only thing we would have to rely on is a unix kernel :P If node does it, I'm sure it would use the kernel too. I dont know any other way to shape traffic.

@astro

This comment has been minimized.

Copy link
Contributor

@astro astro commented Jan 12, 2015

No, iptables is specific to Linux.

@alberto-esposito

This comment has been minimized.

Copy link

@alberto-esposito alberto-esposito commented Jan 12, 2015

yes you are right. I'm studying the source to try to come up with a good solution, since I need this, and to better learn this project.
@feross why you say
(Btw, it doesn't make much sense for the browser version of webtorrent).

?

@astro

This comment has been minimized.

Copy link
Contributor

@astro astro commented Jan 12, 2015

While dropping packets is perfectly valid, this shaping is best done in the actual code.

FWIW here's my approach from Bitford: https://github.com/astro/bitford/blob/master/src/shaper.js
I bet there are similar modules on npmjs.org.

@bradisbell

This comment has been minimized.

Copy link

@bradisbell bradisbell commented Jan 19, 2015

Once implemented, will stream backpressure on the read side slow the download speed?

@astro

This comment has been minimized.

Copy link
Contributor

@astro astro commented Jan 19, 2015

Backpressure should go into https://github.com/feross/bittorrent-protocol/ where it doesn't seem to be implemented at this time. That will only become a problem if download speeds exceed CPU power & disk throughput.

@bradisbell

This comment has been minimized.

Copy link

@bradisbell bradisbell commented Jan 19, 2015

@astro In the download case yes, but when streaming media it is very common that the download speed greatly exceed the playback speed. For example, if you pipe media into VLC, only a couple seconds of media data will be buffered prior to decoding and playback.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Feb 17, 2015

@mbrownnycnyc

This comment has been minimized.

Copy link

@mbrownnycnyc mbrownnycnyc commented Sep 4, 2015

What happened to this issue?

@Deathspike

This comment has been minimized.

Copy link

@Deathspike Deathspike commented Sep 7, 2015

I'm guessing this didn't happen yet?

The stream solution that you provided @feross is only for download streams, right?

It's no way to control upload. I'm pretty new in webtorrent, is any of the libs to seed providing support for throttling?

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Feb 11, 2016

👍

Implementing this seems hard with the way the event loop is ran. It seems to walk the swarm a lot.

@feross feross changed the title Limit download/upload speeds Limit download/upload speeds (throttling) May 17, 2016
@scotttrinh

This comment has been minimized.

Copy link

@scotttrinh scotttrinh commented Aug 25, 2016

I'm working on something similar at work (my application just uploads) and this library works really well: https://github.com/tjgq/node-stream-throttle

You can set up a group with an aggregate rate limit and spin off throttles for each stream. I'm working out issues with changing the speed while connections are in-flight, but if I get it sorted, I'd be happy to take a stab at a PR for this.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Aug 26, 2016

@scotttrinh Yes, that would be much appreciated!

@coleplx

This comment has been minimized.

Copy link

@coleplx coleplx commented Mar 10, 2017

Any update on this?
It would be great to finally be able to limit users connection :)

@scotttrinh

This comment has been minimized.

Copy link

@scotttrinh scotttrinh commented Mar 10, 2017

@coleplx nothing on my end. I wasn't able to get changing the Throttle mid-stream to work for me, but since Webtorrent deals with smaller chunks, maybe it's acceptable to finish the in-flight chunks at the old speed? @feross ? If that's cool, I can put together a PR.

@scotttrinh

This comment has been minimized.

Copy link

@scotttrinh scotttrinh commented Mar 10, 2017

Actually, I just saw #1040. That seems like a reasonable PR for this feature.

@abcd9999

This comment has been minimized.

Copy link

@abcd9999 abcd9999 commented Sep 10, 2017

Hello, I would like to know if this is implemented, and if it is, then how to do it.

@scotttrinh

This comment has been minimized.

Copy link

@scotttrinh scotttrinh commented Sep 11, 2017

@abcd9999 Unfortunately I never got around to it. :(

@quicoto

This comment has been minimized.

Copy link

@quicoto quicoto commented Mar 18, 2018

This seems to have a very low priority although it would have a great impact.

@rogerfar

This comment has been minimized.

Copy link

@rogerfar rogerfar commented Apr 22, 2019

@feross could PR #1040 be re-evaluated again? If there is an issue with it I can have a look at it again.

@DiegoRBaquero DiegoRBaquero mentioned this issue Jun 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.