Skip to main content

I am pretty new to Linux and tctc command and lately I have been looking for a solution to limit bandwidth per connection using the tc commandtc. I have a server application that handles requests from clients consisting of I/O operations, and I want each request to reach a maximum speed of 50MB/s if there is enough bandwidth (but I make sure there are not too many parallel requests such that the bandwidth will go lower than 50MB/s per request). I managed to use tcused tc to limit the bandwidth, but all connections split the 50MB bandwidth/s instead of each connection getting 50MB bandwidth/s. You can see below the tc

tc commands I tried:

sudo tc qdisc add dev eth4 root netem rate 400mbit

or

sudo tc qdisc add dev eth4 root handle 1: htb default 30
sudo tc class add dev eth4 parent 1: classid 1:1 htb rate 100gbit burst 15k

sudo tc class add dev eth4 parent 1:1 classid 1:10 htb rate 400mbit burst 15k
sudo tc class add dev eth4 parent 1:1 classid 1:20 htb rate 400mbit burst 15k 

sudo tc filter add dev eth4 protocol ip parent 1: prio 1 u32 match ip dst 0.0.0.0/0 flowid 1:10
sudo tc filter add dev eth4 protocol ip parent 1: prio 1 u32 match ip src 0.0.0.0/0 flowid 1:20

or, since I am in control of both the server and clients and I know that the server handles clients' requests on port 9000, I tried the following on the clients hostingclient machine:

sudo tc qdisc add dev eth4 root handle 1: prio priomap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sudo tc qdisc add dev eth4 parent 1:2 handle 20: netem rate 400mbit
sudo tc filter add dev eth4 parent 1:0 protocol ip u32 match ip dport 9000 0xffff flowid 1:2

However, none of those solutionsNo solution did what I wantedwant. From what I could understand till now, I think I need to create a class for each port through which requests are being sent, but I do not know them beforehand, since they are not assigned by me, but are automatically selected. In this sense, isIs there a way to create these classes "on the go" or is there another way to achieve this goalsolution?

Thank you for your time and help!

I am pretty new to Linux and tc command and lately I have been looking for a solution to limit bandwidth per connection using the tc command. I have a server application that handles requests from clients consisting of I/O operations and I want each request to reach a maximum speed of 50MB/s if there is enough bandwidth (but I make sure there are not too many parallel requests such that the bandwidth will go lower than 50MB/s per request). I managed to use tc to limit the bandwidth, but all connections split the 50MB bandwidth instead of each connection getting 50MB bandwidth. You can see below the tc commands I tried:

sudo tc qdisc add dev eth4 root netem rate 400mbit

or

sudo tc qdisc add dev eth4 root handle 1: htb default 30
sudo tc class add dev eth4 parent 1: classid 1:1 htb rate 100gbit burst 15k

sudo tc class add dev eth4 parent 1:1 classid 1:10 htb rate 400mbit burst 15k
sudo tc class add dev eth4 parent 1:1 classid 1:20 htb rate 400mbit burst 15k 

sudo tc filter add dev eth4 protocol ip parent 1: prio 1 u32 match ip dst 0.0.0.0/0 flowid 1:10
sudo tc filter add dev eth4 protocol ip parent 1: prio 1 u32 match ip src 0.0.0.0/0 flowid 1:20

or, since I am in control of both the server and clients and I know that the server handles clients' requests on port 9000, I tried the following on the clients hosting machine:

sudo tc qdisc add dev eth4 root handle 1: prio priomap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sudo tc qdisc add dev eth4 parent 1:2 handle 20: netem rate 400mbit
sudo tc filter add dev eth4 parent 1:0 protocol ip u32 match ip dport 9000 0xffff flowid 1:2

However, none of those solutions did what I wanted. From what I could understand till now, I think I need to create a class for each port through which requests are being sent, but I do not know them beforehand, since they are not assigned by me, but are automatically selected. In this sense, is there a way to create these classes "on the go" or is there another way to achieve this goal?

Thank you for your time and help!

I am new to Linux and tc command and I have been looking to limit bandwidth per connection using tc. I have a server application that handles requests from clients consisting of I/O operations, and I want each request to reach a maximum speed of 50MB/s if there is enough bandwidth (but I make sure there are not too many parallel requests such that the bandwidth will go lower than 50MB/s per request). I used tc to limit bandwidth, but all connections split 50MB/s instead of each connection getting 50MB/s.

tc commands I tried:

sudo tc qdisc add dev eth4 root netem rate 400mbit

or

sudo tc qdisc add dev eth4 root handle 1: htb default 30
sudo tc class add dev eth4 parent 1: classid 1:1 htb rate 100gbit burst 15k

sudo tc class add dev eth4 parent 1:1 classid 1:10 htb rate 400mbit burst 15k
sudo tc class add dev eth4 parent 1:1 classid 1:20 htb rate 400mbit burst 15k 

sudo tc filter add dev eth4 protocol ip parent 1: prio 1 u32 match ip dst 0.0.0.0/0 flowid 1:10
sudo tc filter add dev eth4 protocol ip parent 1: prio 1 u32 match ip src 0.0.0.0/0 flowid 1:20

or, since I am in control of both the server and clients and I know that the server handles clients' requests on port 9000, I tried the following on the client machine:

sudo tc qdisc add dev eth4 root handle 1: prio priomap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sudo tc qdisc add dev eth4 parent 1:2 handle 20: netem rate 400mbit
sudo tc filter add dev eth4 parent 1:0 protocol ip u32 match ip dport 9000 0xffff flowid 1:2

No solution did what I want. I think I need to create a class for each port through which requests are being sent, but I do not know them beforehand, since they are automatically selected. Is there a way to create these classes "on the go" or another solution?

Source Link
Ben
  • 41
  • 1
  • 2

How can I limit bandwidth per connection using tc?

I am pretty new to Linux and tc command and lately I have been looking for a solution to limit bandwidth per connection using the tc command. I have a server application that handles requests from clients consisting of I/O operations and I want each request to reach a maximum speed of 50MB/s if there is enough bandwidth (but I make sure there are not too many parallel requests such that the bandwidth will go lower than 50MB/s per request). I managed to use tc to limit the bandwidth, but all connections split the 50MB bandwidth instead of each connection getting 50MB bandwidth. You can see below the tc commands I tried:

sudo tc qdisc add dev eth4 root netem rate 400mbit

or

sudo tc qdisc add dev eth4 root handle 1: htb default 30
sudo tc class add dev eth4 parent 1: classid 1:1 htb rate 100gbit burst 15k

sudo tc class add dev eth4 parent 1:1 classid 1:10 htb rate 400mbit burst 15k
sudo tc class add dev eth4 parent 1:1 classid 1:20 htb rate 400mbit burst 15k 

sudo tc filter add dev eth4 protocol ip parent 1: prio 1 u32 match ip dst 0.0.0.0/0 flowid 1:10
sudo tc filter add dev eth4 protocol ip parent 1: prio 1 u32 match ip src 0.0.0.0/0 flowid 1:20

or, since I am in control of both the server and clients and I know that the server handles clients' requests on port 9000, I tried the following on the clients hosting machine:

sudo tc qdisc add dev eth4 root handle 1: prio priomap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sudo tc qdisc add dev eth4 parent 1:2 handle 20: netem rate 400mbit
sudo tc filter add dev eth4 parent 1:0 protocol ip u32 match ip dport 9000 0xffff flowid 1:2

However, none of those solutions did what I wanted. From what I could understand till now, I think I need to create a class for each port through which requests are being sent, but I do not know them beforehand, since they are not assigned by me, but are automatically selected. In this sense, is there a way to create these classes "on the go" or is there another way to achieve this goal?

Thank you for your time and help!