Recently, I started toying with the concept of dynamically changing the bandwidth instead of using a fixed value. The idea was, for those users who don't consume too much bandwidth within a specified time period, they will be rewarded with a higher bandwidth allocation as compared to those who constantly consume bandwidth within the same time period.
For example, if a user casually spends more time reading website content, less bandwidth is used. As a reward, more bandwidth is allocated for that user so the next time (s)he browses for content, it's a much faster experience. This is in contrast to bandwidth hoggers who constantly download/upload content (e.g. watching video-streaming sites or multi-megabyte file transfers). To lessen the lag other non-hogging users might potentially experience, bandwidth hoggers get allocated lesser bandwidth as penalty.
I wrote the following script that implements this concept. It constantly monitors the bandwidth and changes the allocation depending on the amount of activity during a time period. It's flexible enough to allow changes to settings on-the-fly. The relevant settings are stored in a separate configuration file. You can edit the values to your liking. Before you run the script, make sure the location of the configuration file is referenced correctly in the script by editing the following line:
Code: Select all
CONFIG_FILE="/path/to/dynamic-shaper.settings"
Code: Select all
sudo apt-get install wondershaper
Code: Select all
chmod +x dynamic-shaper.sh
sudo ./dynamic-shaper.sh
Code: Select all
sudo wondershaper clear <interface-name-here>
To run the script on startup, save/move the files to the /root folder, and edit root's crontab settings:
Code: Select all
sudo crontab -u root -e
Code: Select all
# m h dom mon dow command
@reboot /root/dynamic-shaper.sh > /dev/null 2>&1
I hope this is useful or helpful to someone who's in a similar boat.
Thanks to xenopeek for the heads-up about the nstat command.
Script and sample configuration file on the next post.