Speed Limit

vhosting

New Member
Jan 10, 2009
27
0
1
Good Morning,

is possible to limit the speed for each VPS ?
For exmple 2mbit 10mbit etc?

Regards
 
Good Morning,

is possible to limit the speed for each VPS ?
For exmple 2mbit 10mbit etc?

Regards

you may limit per IP using tc linux command

read: http://wiki.openvz.org/Traffic_shaping_with_tc

use the last code (An alternate approch using HTB)

put the VPS IPs here:

CT_IP1=$1
CT_IP2=$2

e.g.

CT_IP1=65.65.65.11
CT_IP2=65.65.65.12

save as .sh, make executable (chmod +x file.sh)
and run with ./file.sh

if you edit the file addin more IPs just re-run it -- it will exclude all existing rules and add it again
 
Last edited:
Thanks for the answer.

I must use this scripts "An alternate approch using HTB" ?

only this parts

CT_IP1=$1
CT_IP2=$2
DEV=venet0
#
tc qdisc del dev $DEV root
#
tc qdisc add dev $DEV root handle 1: htb default 10
#
tc class add dev $DEV parent 1: classid 1:1 htb rate 100mbit burst 15k
tc class add dev $DEV parent 1:1 classid 1:10 htb rate 10mbit ceil 10mbit burst 15k
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 20mbit ceil 20mbit burst 15k
tc class add dev $DEV parent 1:1 classid 1:30 htb rate 30mbit ceil 30mbit burst 15k
#
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10
#
if [ ! -z $CT_IP1 ]; then
tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst "$CT_IP1" flowid 1:20
fi
if [ ! -z $CT_IP2 ]; then
tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst "$CT_IP2" flowid 1:30
fi
#
echo;echo "tc configuration for $DEV:"
tc qdisc show dev $DEV
tc class show dev $DEV
tc filter show dev $DEV

or I must use whole scripts?

You can give me an example (if you can) for limit up/down to 2mbit for only the virtual interface?

very Thanks
 
Thanks for the answer.

I must use this scripts "An alternate approch using HTB" ?

...

very Thanks

use this:

Code:
#!/bin/sh
#
# Incoming traffic control (from whole internet to your vms)
#
# HERE YOU PUT YOUR VMs IPS
# IF YOU LEAVE IT BLANK, IT WILL NOT BE USED
# CT_IP3 is blank then the CT_IP3 limit will be ignored below
CT_IP1=VM_IP_NUMBER_1
CT_IP2=VM_IP_NUMBER_2
CT_IP3=
#set the device name -- if your proxmox have the default config, it is venet0
DEV=venet0
#now we give a name for the rule
tc qdisc del dev $DEV root
#now we create a class inside it (1:)
tc qdisc add dev $DEV root handle 1: htb default 10
#now we set your main server connection (100mbit, 10mbit, etc)
#considering you asked 2mbps per VPS, i think you have 5 VMs and want 2mbps each
#so you probably have 10mbit, i'm right?
tc class add dev $DEV parent 1: classid 1:1 htb rate 10mbit burst 15k
#now we create sections for each speed limit you want to your VMs
tc class add dev $DEV parent 1:1 classid 1:10 htb rate 1mbit ceil 1mbit burst 15k
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 2mbit ceil 2mbit burst 15k
tc class add dev $DEV parent 1:1 classid 1:30 htb rate 3mbit ceil 3mbit burst 15k
#
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10
#this will limit your CT_IP1 (container ip 1) to the 1:10 speed limit (1mbps)
if [ ! -z $CT_IP1 ]; then
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst "$CT_IP1" flowid 1:10 
fi
#this will limit your CT_IP2 (container ip 2) to the 1:20 speed limit (2mbps)
if [ ! -z $CT_IP2 ]; then
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst "$CT_IP2" flowid 1:20 
fi
#this will limit your CT_IP3 (container ip 3) to the 1:30 speed limit (3mbps)
if [ ! -z $CT_IP3 ]; then
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst "$CT_IP3" flowid 1:30 
fi
#
echo;echo "tc configuration for $DEV:"
tc qdisc show dev $DEV
tc class show dev $DEV
tc filter show dev $DEV
#
# Outgoing traffic control (from your vms to the whole internet)
#
DEV=eth0
#
tc qdisc del dev $DEV root
#
tc qdisc add dev $DEV root handle 1: htb default 10
#
tc class add dev $DEV parent 1: classid 1:1 htb rate 10mbit burst 15k
tc class add dev $DEV parent 1:1 classid 1:10 htb rate 1mbit ceil 1mbit burst 15k
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 2mbit ceil 2mbit burst 15k
tc class add dev $DEV parent 1:1 classid 1:30 htb rate 3mbit ceil 3mbit burst 15k
#
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10
#
if [ ! -z $CT_IP1 ]; then
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip src "$CT_IP1" flowid 1:10
fi
if [ ! -z $CT_IP2 ]; then
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip src "$CT_IP2" flowid 1:20
fi
if [ ! -z $CT_IP3 ]; then
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip src "$CT_IP3" flowid 1:30
fi
#
echo;echo "tc configuration for $DEV:"
tc qdisc show dev $DEV
tc class show dev $DEV
tc filter show dev $DEV

you can add CT_IPs freely, just change the flowid at the end of the command to match the limit you want to use.
you don't need to create more classes if you want to limit 2 or more vms to the same speed.

e.g.: if your CT4 need a 2mbps limit, just copy the "if ct_ip2" etc part, rename to ct_ip4. since it follow the flowid 1:20 it will be capped to 2mbps

sorry my english
 
thanks :) last information, this scripts I must run from general root access right?

Thanks (english is ok I understend)
 
#considering you asked 2mbps per VPS, i think you have 5 VMs and want 2mbps each
#so you probably have 10mbit, i'm right?


In my server I have 100mbit but I not want give 100mbit at all vps I want give 2mbit until 10mbit for each vps (depends from the price)

:)

I use 2mbit 5mbit and 10mbit unlimited transfer for each vps. But the server is 100mbit
 
then, change it:

Code:
tc class add dev $DEV parent 1: classid 1:1 htb rate 10mbit burst 15k

to:

Code:
tc class add dev $DEV parent 1: classid 1:1 htb rate 100mbit burst 15k
 
tc class add dev $DEV parent 1:1 classid 1:100 htb rate 10mbit ceil 10mbit burst 15k

tc qdisc add dev $DEV parent 1:100 handle 100: sfq perturb 10

if [ ! -z $CT_IP3 ]; then
tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst "$CT_IP3" flowid 1:100
fi

For set 10mbit this 3 string are correctly?
 
the class ids 1:10, 1:20 are just references to each limit rate. it doesn't need to be changed. just be sure to use 1:10, 1:20, etc on flowid for each IP inside the if statements
 
just a last note: the tc will not "hardlimit" the connection, it works more like a balancing tool, for what i tested, but i think will you find the tips below help to make a better use of all the bandwidth your server have. if you want to set some kind of "guaranteed" bandwidth for a vm but allow it to take more bw when not all bw is in use, you can change the ceil numbers. see..

you have 100mbps to distribute for 10 vms (4 with 5mbps, 5 with 10mbps and 1 with 30mbps). the sum of all vms is exactly 100. but considering not all vms will use all the bandwidth at the same time, you can set they this way:

tc class add dev $DEV parent 1:1 classid 1:10 htb rate 5mbit ceil 10mbit burst 15k
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 10mbit ceil 20mbit burst 15k
tc class add dev $DEV parent 1:1 classid 1:30 htb rate 30mbit ceil 50mbit burst 15k
#note i put a 5mbit rate and 10mbit ceil, it means class 1:10 can use up to 10mbit
#however, when other classes need more bw, it may be gradually reduced to 5mbit

I forgot also to warn you about the htb default. its '10' on the configuration i sent you. then, all IPs not configurated on the script, will be put on the 1:10 class.

Also, do not forgot to change "1: classid 1:1 htb rate 10mbit" to 100mbit on the outgoing script too, or your upload will be capped to 10mbits (and you said you have 100).

the prior number (set as 1 on this script for all IPs) may be set to a higher number for the LESS important vms (e.g., your own test VMs). if you create a 11st VM for your personal use, for example, set it this way:

tc filter add dev $DEV protocol ip parent 1:0 prio 5 u32 match ip src "$CT_IP11" flowid 1:10

note it have prio 5 (while all others are prio 1). it means your VM will have 5-10mbits to use, but ALL the bw (even the 5mbps rate) may be "stolen" if the other VMs are requesting bw -- good if your other 10 VMs (customers) are hosting VPS, cause they rarely needs too much bw at the same time. not good if they are for torrent seeding, file servers, etc, because all VMs will request more and more bw almost all the time, then your 11st VM will never have bw to use, because it have less priority than all other VMs.

if you have some kind of "unusual" VMs, or one of each type (one for file server, other for hosting, other for remote access, etc) it may be confusing to set a high number classes. you can then try http://tcng.sourceforge.net/ -- tcng have an easier "scripting" language for high number of VMs.

good luck
 
hi there and as usual thanks !

We have 9 cluster running, 43 vps inside without limit @!#! (they are eating all our bw ) We must run this script in each node putting the ip i want to limit ?

Diego
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!