Two web servers are started at ports 8080 and 8081, but clients still contact the server machine at port 80 as usual. To achieve this, a forwarding rule is created using the command:
tcpchains -A a -p 80 -o 8080
tcpchains -a a -p 80 -r 8081 -i
128.143.0.0 -m 255.255.0.0
All the clients from the network 128.143.0.0 (premium users) will be served by the web server at port 8081. There are several ways to let the premium users experience shorter delay:
In previous example, we can only provide shorter delay for premium users. In this example, we can further guarantee their delay being no longer than some value, say 2 seconds. This can be done with the help of ControlWare. Please read its project homepage and tutorial for further information. We write a simple program using ControlWare, and use this program as the QoS manager. Before starting the QoS manager, we first create the forwarding rule as the first example.
tcpchains -A a -p 80 -o 8080
tcpchains -a a -p 80 -r 8081 -i
128.143.0.0 -m 255.255.0.0
Note that we don't need to create a socket group this time, since ControlWare will do it for us. The configuration file of ControlWare should be similar to the following (some component's parameter values are just for demonstration purpose)
DirServer
NoServer
ModulePath /home/rz5b/controlWare/lib
Period 30
Delay 120
QoS delay
CREATE ctrl AS PIController;
CREATE cmp AS comparer;
CREATE act AS acceptRate;
CREATE sensor AS netsensor;
CONNECT sensor[3] TO cmp.input[0];
CONNECT cmp[0] TO ctrl.input[0];
CONNECT ctrl[0] TO act.input[0];
QoS END
COMPONENT cmp 2 # set point is 2 seconds
COMPONENT ctrl 0.7, 0.3, 1, 0, 1, 100
# ZERO = 0.7, GAIN = 0.3, initial output is 1, initial
error is 0,
# output must be within the range [1:100]
COMPONENT act 8080, 1000, 1
# port number is 8080, initial accept rate is 1000 per
second, process should be blocked
COMPONENT sensor 8081, 0
# we are interested in the delay of port 8081 during
each sampling period
We use the provided component netsensor to collect the delay information of port 8081 and acceptRate actuator to change the accept rate of port 8080. A simple control loop is used to dynamically adjust the accept rate of port 8080 according to the delay of port 8081.
When the server is overloaded, content degradation is one possible way to reduce the server load. Content degradation is to deliver low quality content to save CPU cycles and bandwidth. Two instances of web server are started at ports 8080 and 8081, respectively. The server at port 8080 is equipped with full content, while the one at port 8081 is equipped with degraded content. A probability forwarding rule is created to forward 30% of the connections to the server with degraded content:
tcpchains -A a -p 80 -o 8080
tcpchains -a a -p 80 -r 8081 -c 3000
Note that, the forwarding probability can be dynamically changed at runtime.
In this example, we demonstrate how to give shorter delay to the premium users. As in example 1, clients are first classified according to their IP address. Connections from the premium users are forwarded to the port 1143, the others are forwarded to the one at port 2143. Finally, the connection accept rate of port 2143 is limited to 10 per second. Since IMAP server (IMPAD by UW) is started by xinetd, xinetd need to be modified as follows:
service imap
{
disable =
yes
id = imap
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/sbin/imapd
}
service ximap
{
disable = no
id = ximap
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/sbin/imapd
}
service yimap
{
disable = no
id = yimap
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/sbin/imapd
}
Also, the following is added to file /etc/services:
ximap
1143/tcp imap2
yimap 2143/tcp imap2
And, the following commands are used to configure the kernel:
tcpchains -A a -p 143
-o 2143
tcpchains -a a -p 143 -r 1143 -i 128.143.0.0 -m 255.255.0.0
skex -A aa -n 2143 10
In this example, we demonstrate how to limit the bandwidth usage of one class of clients. As in example 1, clients are first classified according to their IP address. Connections from the premium users are forwarded to the FTP server at port 1021, the others are forwarded to the one at port 2021. Finally, the basic clients are limited to use less than 1M.
tcpchains -A a -p 21
-o 2021
tcpchains -a a -p 21 -r 1021 -i 128.143.0.0 -m 255.255.0.0
skex -A af 1021 1048576