Bandwith Limiter

Suggest, post, or discuss plugins for Deluge
Post Reply
compu73rg33k
Member
Member
Posts: 15
Joined: Tue Feb 05, 2008 5:24 am

Bandwith Limiter

Post by compu73rg33k »

I'm at a University that limits our bandwith usage to 2GB/day. We get pretty good speeds (10mb/s down, 1 mb/s up), so I'm bummed I have to resort to limiting the upload speed to 30KB/s so that it doesn't upload too much in one day. It'd be nice if you could set a bandwith limit that would obey any speed limits, including unlimited, and then not upload at all once the limit is reached. Our bandwith usage updates once an hour, and you can't have downloaded more than 2GB in any 24 hour period. If you do, you get throttled to 1mb/s down, 32kb/s up. Big bummer, especially the upload speed. I have basic knowledge in python and would be willing to try to help with this. Comments?
johnnyg
Top Bloke
Top Bloke
Posts: 1522
Joined: Sun Oct 28, 2007 4:00 am
Location: Sydney, Australia

Re: Bandwith Limiter

Post by johnnyg »

I think it's a great idea.

I had a similar idea of a plugin that checks the internet usage (monthly).

the general idea is that deluge somehow knows when it's about to go over your allowed usage and stops in time :D

writing a plugin to do the actual limiting wouldn't be too hard, the hard part would be having deluge universally be able to check how much it had downloaded/uploaded.

the two solutions that come to mind are:
  • have deluge keep track of its own usage: this of course wouldn't be as good (not to mention redundant) but it would mean it would work everywhere.
  • have deluge interact with a site-specific parser using a standard interface: this would mean you would just need to write the parser for your usage site for the plugin to be able to work.
compu73rg33k
Member
Member
Posts: 15
Joined: Tue Feb 05, 2008 5:24 am

Re: Bandwith Limiter

Post by compu73rg33k »

If anybody's wants to look at the code or help, please do! I don't know much python, but I really want this script! So I'm going to be learning as I go along. I've basic python knowledge, but not anything too technical.

Paste: http://pastesite.com/2212
Live File: http://dl.getdropbox.com/u/124437/delug ... limiter.py
have deluge interact with a site-specific parser using a standard interface: this would mean you would just need to write the parser for your usage site for the plugin to be able to work.
I don't follow, can you explain a little bit more?
mvoncken
Developer
Developer
Posts: 225
Joined: Mon Sep 03, 2007 9:38 pm

Re: Bandwith Limiter

Post by mvoncken »

compu73rg33k wrote:
have deluge interact with a site-specific parser using a standard interface: this would mean you would just need to write the parser for your usage site for the plugin to be able to work.
I don't follow, can you explain a little bit more?
Don't worry about that, it's about using the stats provided by (private) torrent-sites to calculate the amount downloaded.
But there's nothing standard about that, the approach we discussed on irc is better.
dev: webui, core, labels | irc:vonck7 |
johnnyg
Top Bloke
Top Bloke
Posts: 1522
Joined: Sun Oct 28, 2007 4:00 am
Location: Sydney, Australia

Re: Bandwith Limiter

Post by johnnyg »

I was actually referring to how ISPs normally provide usage stats but like mvoncken said, there is nothing standard about the way they do it (hence why you would need a parser for each site).
The advantage of using an ISP usage site is that it would incorporate all usage not just deluge's.
compu73rg33k
Member
Member
Posts: 15
Joined: Tue Feb 05, 2008 5:24 am

Re: Bandwith Limiter

Post by compu73rg33k »

Just to beat a dead horse...

I don't think I'd like it to monitor exactly up to my 2GB/day limit. I'm thinking I could reserve ~1.5GB/day to deluge, but I wouldn't want it to be able to go all the way up to my 2GB. I feel like that would end in bandwith jail a lot haha.
compu73rg33k
Member
Member
Posts: 15
Joined: Tue Feb 05, 2008 5:24 am

Re: Bandwith Limiter

Post by compu73rg33k »

I've made some progress.
Direct Download: http://dl.getdropbox.com/u/124437/delug ... limiter.py
PasteSite: http://pastesite.com/2267

I have some questions on how to proceed.
First, why do I keep seeing set_core_uri() in all the examples? What does this really do in terms of the plugin?

For setting the max_bandwith_limit
How should I set and store it's configuration value? Can/Should I create a new string variable using set_config ?

For storing the data transfer log
How should I store this dictionary so that it can be recalled? vonck7 pointed me in the direction of pickle which I understand serializes the data. But how will this be stored so that it can be repetitively accessed by the program?

Lastly, I need some help with the logic for the plugin. How should I go about storing the data transferred? I was thinking maybe storing the data for each half hour, so then if it reaches its max bandwith for the past 24 hours, it won't start again until the next half hour block. I guess I'd have to create a dictionary within the log dictionary I'm already creating so it'd basically be a multi-dimensional dictionary. e.g.
data_log{ 1:{0000:242342}, 2:{0030:724722}, 3:{0100:357273} 4:{0130:1275828} }
Where 1, 2, 3, 4 are the torrent ids
0000, 0030, 0100, 0130 are the time blocks (12:00AM-12:30AM, 12:30AM-1:00AM, 1:00AM-1:30AM, 1:30AM-2:00AM
242342, 724722, 357273, 1275838 are the total data transferred in its respective time blocks

And then after I got the initial idea working, I thought it'd be nice to be able to specify individual bandwith limits for downloading and uploading, so I guess another dimension would be added to the scheme so that it looked like:
data_log{ 1:{0000:{"upload":124273,"upload":137247}}, 2:{0030:{"upload":324724,"download":423473}}, 3:{0100:{"upload":147237, "download":162374}}, 4:{0130:{"upload":572357, "download":575838}} }

If anyone has any other suggestions I'm more than open to them. I'm not experienced with python, so I'm trying to learn more of the language as I write this plugin.
mvoncken
Developer
Developer
Posts: 225
Joined: Mon Sep 03, 2007 9:38 pm

Re: Bandwith Limiter

Post by mvoncken »

Did you test that script ?, I don't think it works.
sclient.set_core_uri() connects to the daemon, you only have to do that once, after importing.

Because you don't know lots of python i would advise you to have a short edit->run coding cycle so you can see your changes in action.

For the commandline- prototype :
Just use a dict for all settings like :
settings = {option:value , max_bandwith_limit:20000,period:60*60*24 } , and forget about option parsing.

focus on :
*maintaining the 24hour period , and having a start/stop trigger for that period -> 0:00 at night? , and think about period's that start once a month/once a week.
*re-enabling download at the start of a new fresh period.
*storing global total upload/download stats using pickle. (not per torrent) {'total_down_at_start_of_period':999,'total_up_at_start_of_period':888}
*diff 24hour period with totals above to see download for that day.

Postpone:
-detecting deleted/removed torrents until you start with the real plugin.
-individual limits, you're not far enough with the rest.

Once you get the above going i'll post a little wiki tutorial about creating a core-plugin with an interval, (detecting removed torrents is easy there.)
For setting the max_bandwith_limit
How should I set and store it's configuration value? Can/Should I create a new string variable using set_config ?
You just use sclient.set_config.
For storing the data transfer log
How should I store this dictionary so that it can be recalled? vonck7 pointed me in the direction of pickle which I understand serializes the data. But how will this be stored so that it can be repetitively accessed by the program?
http://docs.python.org/lib/pickle-example.html
We're not a python help-site, I do expect you to figure out some things yourself, good luck :D.
dev: webui, core, labels | irc:vonck7 |
compu73rg33k
Member
Member
Posts: 15
Joined: Tue Feb 05, 2008 5:24 am

Re: Bandwith Limiter

Post by compu73rg33k »

Started on the plugin file.
Source here: http://pastesite.com/2486
shmeii

Re: Bandwith Limiter

Post by shmeii »

I managed to write a full plugin that does approximately what you want.

Note that it doesn't directly work, because of bug #881 (update method is not called), but there is a patch available on the bug report.

To apply it (assuming you are on linux), you must cd to the deluge main directory, which is either /usr/lib/pythonX.X/site-package/deluge/ or /var/lib/python-support/pythonX.X/deluge/ depending on your distribution, and then enter patch -p 0 < /path/to/patch
Attachments
BandwidthLimiter.egg
(15.29 KiB) Downloaded 269 times
Post Reply