Experience in bandwidth control in Linux

Source: Internet
Author: User
Linux's experience in bandwidth control-Linux Enterprise applications-Linux server application information. The following is a detailed description. In Linux, bandwidth control is implemented through queues. The principles are latency and Token. In addition, cbq queues are widely used. The joke is that this is exactly the most complicated and difficult queue, and the document is hard to understand. Now there is a new htq queue which is relatively easy to configure, but requires manual kernel compilation to support it.

In fact, if cbq has a Chinese document, it may be easier to understand. : O

The basic steps for using cbq are as follows:
1) bind a CBQ queue to network physical devices (such as the ethernet card eth0)

2) create a category on the queue

3) create a filter for each category

The configuration and comments may be clear. Even if the network is connected through adsl dial-up, a single network card is used.

Tc qdisc del dev eth0 root # Delete the previous queue

Tc qdisc add dev eth0 root handle 100: cbq bandwidth 10 Mbit avpkt 1000

# Bind a queue to eth0 with a physical bandwidth of 10 Mbit

Tc class add dev eth0 parent 100:0 classid 100cbq bandwidth 10 Mbit rate 10 Mbit allot 1514 weight 2 Kbit prio 8 maxburst 8 avpkt 1000 bounded

# Create a root class. The root class has no speed limit. Therefore, the actual speed of adsl is not specified, instead of the speed of the NIC.

Tc class add dev eth0 parent 100classid 100:2 cbq bandwidth 10 Mbit rate 10 Mbit allot 1513 weight 1 Mbit prio 5 maxburst 8 avpkt 1000 bounded

# The first subclass is for ip addresses that require full speed, for example, p

Tc class add dev eth0 parent 100classid 100:3 cbq bandwidth 10 Mbit rate 1000 Kbit allot 1513 weight 100 Kbit prio 6 maxburst 8 avpkt 1000 bounded

# The second subclass is used by other users in the CIDR block.

Tc qdisc add dev eth0 parent 100:2 sfq quantum 1514b perturb 15
Tc qdisc add dev eth0 parent 100:3 sfq quantum 1514b perturb 15

# Sfq is another queue, which means that the order of data packets passing through the 100:2 and 100:3 sub-classes is random, rather than the default fifo, for example, if you download the file first and then open ie, the ie page will not be displayed after loading.

Tc filter add dev eth0 parent 100:0 protocol ip prio 25 u32 match ip dst 192.168.202.219/32 flowid 100:2
Tc filter add dev eth0 parent 100:0 protocol ip prio 25 u32 match ip dst 192.168.202.245/32 flowid 100:2
Tc filter add dev eth0 parent 100:0 protocol ip prio 25 u32 match ip dst 192.168.202.216/32 flowid 100:2
Tc filter add dev eth0 parent 100:0 protocol ip prio 25 u32 match ip dst 192.168.202.218/32 flowid 100:2
Tc filter add dev eth0 parent 100:0 protocol ip prio 25 u32 match ip dst 192.168.202.0/24 flowid 100:3

# Create a filter based on the category and create a filter based on the destination ip address.

In linux, to control the bandwidth, you can only control the sent packets, but not the received packets. Because the speed at which others send packets to you cannot be controlled by you. Therefore, we need to limit the download speed of adsl, not on the ppp0 interface, but on the eth0 interface, that is, the intranet data sending interface.

Even more confusing is that the rate flag speed is not accurate. When it is set to 10 Kbps or 10 kbit, the download speed is kept at around 10 kb/s. It should be 10 kbit/8/1024 kb/s. So I simply use the bandwidth index to determine the rate.

The important parameter is bounded, indicating to limit this bandwidth. If no, the category occupies all bandwidth when the line is idle.

In addition to bounded, you can also set borrow, Isolated, sharing. Borrow can borrow the bandwidth of another category. Isolated designates a certain part of the bandwidth for the specified category. Even if there is no data transfer for that category, this part of the bandwidth will not be allocated to others. Sharing and Isolated are the opposite.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.