Every serious home-server should have aMule installed as daemon.
Unfortunately aMule, like all p2p programs, can slow down our connection, even if we aren’t downloading a thing or if we have few downloads remaining, because it use the upload bandwidth to share the downloaded files. We can lower the upload bandwidhth limit but if we lower it too much we will consequently download very slowly.

amule

Instead of continually, manually change the upload limit according to our needs, I use a little script that I wrote, that automatically set the bandwidth limits from the number of downloads in the queue. To use this script we must have the amulecmd utility installed (from source code or from distro packages).

The script in his defaults settings sets the upload limit to 2KB/s if there aren’t file in the downlaod queue; if there are three files or less, the upload limit is setted to 10KB/s; in the other cases (more of three files downloaded), the upload is setted to 30KB/s.
The beginning of the script contains well commented parameters to change the script behaviour.

#!/bin/sh

#password to connect to the amule daemon
PASSWORD="abc"
#command to execute to connect to the daemon
AMULE_COMMAND="amulecmd"
#upload limit when there is no file in the download queue
IDLE_BW_UP=2
#min number of files in download queue to set the upload limit
#to the "normal" value
MIN_DW_LIMIT=2
#upload limit when the number of file in download queue is >= 1
#and  MIN_DW_LIMIT
NORMAL_BW_UP=30

UP_LIMIT="set bwlimit up "
DW_LIMIT="set bwlimit down "
COMMAND="$AMULE_COMMAND -P$PASSWORD -c"

if [ -z "$(pgrep amuled)" ]; then
    #echo "amule closed"
    exit
fi

setUploadBw()
{
    CURR_BW_UP=`expr substr "$($COMMAND "get bwlimits" | grep "Up")" 24 2`
    if [ "$CURR_BW_UP" -ne "$1" ]; then
        $COMMAND "$UP_LIMIT $1" > /dev/null
        $COMMAND "$DW_LIMIT 0" > /dev/null
        echo "$0: Upload bandwidth limit is now $1 kB/s"
    fi
}
NDOWN=$($COMMAND "show dl" | grep -c ">")

if [ "$NDOWN" -le 0 ];then
    setUploadBw $IDLE_BW_UP
else
    if [ "$NDOWN" -le "$MIN_DW_LIMIT" ]; then
        setUploadBw $MIN_BW_UP
    else
        setUploadBw $NORMAL_BW_UP
    fi
fi

To use the script, paste it to a file named “setamulebandwidth”, modify the parameters you need, and save it to /usr/bin. After that, set the execution rights to the script:

#chmod a+x /usr/bin/setamulebandwidth

Of course we want to execute thes script automatically at least every 5 minutes (personally, I prefer to run it every minute), and to do that we can use the cron.
Type from your administrative account (add sudo at the start of the command if you are using Ubuntu):

# sudo crontab -e
and add the following line
*/5 * * * * /usr/bin/setamulebandwidth

Where the */5 means that the script will executed every 5 minutes.
Save the file.

Now your aMule will change the upload limit dinamically from the number of downloads in queue! :D


Se sei interessato a questo post, potresti anche provare a leggere:

  • No related posts