Turgut Kalfaoglu
Regular Contributor
This is the script I wrote to automatically throttle transmission based on the ping values to our uplink..
It features fast download throttling against impulse usage, and pause before re-increasing the download speed if it was recently lowered.
Feel free to use it, but you will need ooRexx installed.
It features fast download throttling against impulse usage, and pause before re-increasing the download speed if it was recently lowered.
Feel free to use it, but you will need ooRexx installed.
Code:
#!/opt/bin/rexx
/* Automatic Transmission throttle based on the ping values from your next hop.
By Turgut Kalfaoglu <turgut@kalfaoglu.com>
Usage: start this script with the quiet option for regular use. quiet option prevents output to screen.
For example: in /jfss/bin/services-start :
/usr/bin/nohup /opt/bin/transmission-throttle quiet &
may be used to start it
Requires OOrexx
Outputs to /opt/var/log/transmission-throttle.log
*/
parse arg quiet
if quiet='quiet' then quiet=1
else quiet=0
login = 'root:itspassword' /* transmission RPC login infomation - set it in transmission config */
speed=900 /* initial speed in bps */
minspeed=10 /* minimum bps possible */
maxspeed=1500 /* maximum bps you want transmission to use */
threshold = 70 /* in ms - we try to keep pings below this value */
steps = 50 /* lower/increase speed by "steps" bps */
targetip = "71.16.10.1" /* The IP of your uplink - at telecom. do a traceroute www.kalfaoglu.net to find out your next hop */
"/opt/bin/transmission-remote --auth" login "-d " minspeed ">/dev/null"
'/opt/bin/rxqueue /clear'
lastlowered=time('R')
lastlowered=time('E')
do forever
setspeed=0
"ping -W 5 -c 3" targetip "| grep round | /opt/bin/rxqueue"
if queued()>0 then do
oldspeed=speed
parse pull "min/avg/max =" .'/'line'/'.
if quiet=0 then say 'avg ping:' line 'ms'
if line>threshold*2 then do /* is the line VERY busy? decrease it a lot */
speed=speed-(steps*2)
lastlowered=time('E')
if speed<minspeed then
speed=minspeed
else
if quiet=0 then say 'speed lowered by' steps*2
end
if line>threshold then do
lastlowered=time('E')
speed=speed-steps
if speed<minspeed then
speed=minspeed
else
if quiet=0 then say 'speed lowered by' steps
end
if line<threshold then do
if time('E')-lastlowered>30 Then do
speed=speed+steps
if speed>maxspeed then
speed=maxspeed
else
if quiet=0 then say 'speed raise by' steps
end
else /* will not raise right after lowering it.. */
if quiet=0 then say 'cannot raise speed yet' trunc(time('E')-lastlowered) 'secs elapsed'
end
if oldspeed<>speed then do
if quiet=0 then say 'speed changed.. setting transmission to ' speed
'/opt/bin/transmission-remote --auth' login '-d' speed '>/dev/null'
'echo' date() time() 'ping' line 'current speed' speed '>> /opt/var/log/transmission-throttle.log'
end
end
'/opt/bin/rxqueue /clear'
'sleep 5s'
end