Options for bandwidth management on a shared internet connection
Solution 1
If I were to build something to solve this problem, I would setup this :
We are here going to take your example of 4 computers sharing one link. The network would be shaped like this :
{ ISP }=========[ SOHO router] ===LAN1=== [eth0 |Linux Box| eth1] ===LAN2=== Home Desktops/Laptops
Let's say you use static IP addressing in LAN2:
Linux Box 192.168.1.1
Home 1 192.168.1.11
Home 2 192.168.1.12
Home 3 192.168.1.13
Home 4 192.168.1.14
I would first write a small script to detect which clients are up by pinging them and writing result somewhere. "This is left as an exercise for the reader" Calculate the total number of connected hosts (1-4)
Be sure to handle the case of no hosts online.
Divide the total bandwith but the number of connected hosts. (12Mb for 1, 6Mb for 2, 4Mb for 3, 3Mb for 4)
Next use tc with the HTB algorithm to limit the bandwidth of each address on WAN-side device. First, create the root class :
DEV="eth0"
TC="/sbin/tc"
TOT_BW=12
$TC qdisc add dev $DEV root handle 1: htb default 99
Then, add a class for each "client" (Here, for example, 3 clients)
NB_CLT=3
CLT_BW=$(($TOT_BW/$NB_CLT))mbit
for i in seq $NB_CLT
do
$TC class add def $DEV parent 1: classid 1:$i htb rate $CLT_BW ceil $CLT_BW burst 15k cburst 1500
$TC filter add dev $DEV protocol ip parent 1:0 prio 1 flowid 1:$i u32 \
match ip dst 192.168.1.1$i/32 \
match ip src [Router IP in LAN1]/32
done
(above script is totally untested and NOT typing-error-free)
Now you still have to properly script that to be run every minute and renew buckets/filters every time a new host goes up or down.
I hope that will point you in the right direction, good luck.
Alternate Solution
Install a local QoS software on all hosts to restrict their bandwidth. I Personnaly use NetLimiter (Non-free)
Solution 2
OpenWRT does seem to support it, though I have never used it myself. You can take a look at the Network Traffic Control page on their website, and especially the second example: plain simple bandwidth sharing (aka traffic shaping) with HTB. This involves simple calls to qdisc, so any Linux box could do it.
Related videos on Youtube
BlackList96
Updated on September 18, 2022Comments
-
BlackList96 over 1 year
For the last few days, I was trying to implement the KMeans algorithm using SciKit Learn, But I came across a very confusing problem. I have a dataset that has two class labels
['ALL', 'AML']
whereALL has 47
andAML has 25
samples and100
attributes to train from and now I want to use this dataset for KMeans clustering so that I can compare the predicted results with the original class labels. Before asking my question let me explain certain scenarios. In all the scenarios I have taken all the100
attributes to fit the model.Scenario 1:
In the first run, I started with a model that is created with pretty much default arguments i.e.
model = KMeans(n_clusters=2)
. For comparing the predicted class labels(which are numeric) with the original labels(which are strings), I set the original class labels asALL = 1
andAML = 0
. After that, while comparing using a classification report I got an average accuracy of35%
. Then I run the algorithm once again and got an accuracy of44%
. For the third try, I got33%
and so on.However, I looked about it and came to know that the
random_state
argument needs to have a fixed value to get same accuracy throughout all runs.Scenario 2:
After knowing about
random_state
, this time I started with random state 0 and created the model asmodel = KMeans(n_clusters=2, random_state=0)
and kept the original class labels as before i.eALL as 1
andAML as 0
. However, this time the output didn't change on different runs and I got an accuracy of53%
. But, out of curiosity, I swap the original class label i.e. I setALL as 0
andAML as 1
which results in47%
.Scenario 3:
This time I choosed
random_state
as1
i.e.model = KMeans(n_cluster=2, random_state=1)
and havingALL as 0
andAML as 1
gave67%
accuracy while consideringALL as 1
andAML as 0
gave33%
accuracy.So, My question is what I am doing wrong here? Am I implementing something wrong? If I am right then why the result is changing so much depending on random_state and class labels? What's the solution and how to choose the best pair of random_state and class labels?
-
pmdj almost 11 yearsI notice that that example is for the upload side. I'm currently reading my way through the Linux Advanced Routing & Traffic Control HOWTO which seems somewhat promising though and hopefully allow me to make sense of all these
tc
rules. Linux' traffic shaper certainly is looking promising. -
mveroone over 9 yearsProblem with my approach is that every host up reduce the other's bandwidth even if they don't use all their share. But designing something that enforces sharing only when the demand is high... is difficult.
-
DavidPostill almost 7 yearsPlease do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by voting to close it as a duplicate or, if you don't have enough reputation for that, raise a flag to indicate that it's a duplicate. Otherwise tailor your answer to this question and don't just paste the same answer in multiple places.
-
ndemou almost 7 years@DavidPostill I thought about voting to close as a duplicate but hesitated because this is a 3 year old question. I even searched meta.superuser and found a relevant question at meta.superuser.com/questions/3524/…. After reading the meta I think that the situation is complicated (I have an answer for two old questions with enough discussion in each one) and leaving a short pointer answer seems at least "not bad". I'm open to hear your thoughts though.