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!