SME server resources
The original wondershaper
I have a pretty busy website which is eating up my upload bandwidth. I have always been using traffic shaping, but recently my web-surfing became increasingly sluggish and slow.
I used to use wondershaper original, which you can find here, with some extra documentation. Be carefull, because I have filled in the values of the upload and download.
The wondershaper script in the end did not help enough because it cannot easily prioritise all kinds of traffic. I needed to give outgoing webtraffic lower priority.
Therefore I adjusted scripts from the internet to make two new wondershaper scripts.
The totally re-written and revised wondershaper on steroids
I am now using a new HTBWondershaper, based on HTB. It works fine and can do a lot more. It works on kernel 2.6.X, but perhaps also 2.4
It is very well documented I think. Please give feed-back, positive and negative.
What does HTBWonderhaper do?
This HTBWondershaper script implements traffic shaping: it filters outgoing traffic into classes and then sets limits/prioritises these classes. Each class gets a lower and upper bandtwith limit. Each class also has a priority, and if the prio is lower, the traffic goes first.
#Shaping: The process of delaying packets before they go out to make traffic confirm to a configured maximum rate. Shaping is performed on egress (outgoing traffic). Colloquially, dropping packets to slow traffic down is also often called Shaping.
Policing: Delaying or dropping packets in order to make traffic stay below a configured bandwidth. In Linux, policing can only drop a packet and not delay it - there is no 'ingress queue'.
# Strength of the tactics of this script is:
- It uses HTB filter: this guarantees minimum bandtwith per class and devides surplus bandtwith evenly
- It uses "iptables marks" to filter traffic into classes. This means you can use the rather simple iptables language to put specific traffic into TC classes rather than the complex non-documented TC stuff.
- EXAMPLE to show its simplicity
-
#For download speed, for instance: pin network 192.168.2.0 behind this server down to 50 Kb/s DOWNload (=~ 6kB)
#(so use internal interface for classes, internal here is eth0):
tc qdisc add dev eth0 root handle 1: htb default 13
tc class add dev eth0 parent 1: classid 1:1 htb rate 10000kbit ceil 10000kbit
-
#make class with 50kb ceiling:
tc class add dev eth0 parent 1:1 classid 1:14 htb rate 10kbit ceil 50kbit prio 5
tc qdisc add dev eth0 parent 1:14 handle 140: sfq perturb 10
-
#filter traffic mark 9 into it (set handle to 9):
tc filter add dev eth0 parent 1:0 protocol ip prio 5 handle 9 fw classid 1:14
- Once you have the class into place you can mark all kinds of traffic to fall into it.
#set with iptables "mark 9" in specific traffic
iptables -t mangle -I FORWARD -d 192.168.2.0/24 -j RETURN
iptables -t mangle -I FORWARD -d 192.168.2.0/24 -o eth0 -j MARK --set-mark 0x9
-
# watch it:
tc -s qdisc show dev eth0
tc -s class show dev eth0
tc -s filter show dev eth0
-
#delete it again:
tc qdisc del dev eth0 root 2> /dev/null > /dev/null
iptables -t mangle -F
-
#For download speed, for instance: pin network 192.168.2.0 behind this server down to 50 Kb/s DOWNload (=~ 6kB)
#(so use internal interface for classes, internal here is eth0):
The pimped up wondershaper
Before HTBWondershaper I used this adjusted wondershaper script, which also worked very nicely. It is however much less easy to adjust, given the worrysome TC language. It worked fine too though.
I adjusted the wondershaper script, to make sure the traffic from my local website does not cut off my upload to internet, which I need to surf. To do that I added a variable that makes dns requests from me to internet faster (because dns was very slow), and I have put upload traffic from my webserver to internet, with source port 80 in a queue that has less priority. The beefed up wondershaper lives here