About Linux server traffic and Concurrency Control

Source: Internet
Author: User

About Linux server traffic and Concurrency Control

This article describes how to use the tc tool to implement advanced traffic control for Linux. The TC traffic control tool has been incorporated into the kernel since Linux2.2 and has very powerful functions. If you need to build a high-performance Linux gateway, this article will benefit you a lot.

I. the Linux traffic control process is divided into two types:

1. queue control is QOS, And the sending queue rules at the bottleneck are usually controlled by sfq prio.

2. Traffic Control, that is, bandwidth control, queue shaping, generally TBF HTB

2. There are two Linux traffic control algorithms:

1. classless algorithms are used for leaf-level queues without branches, for example, SFQ

2. classification algorithms are used in queues with multiple branches, such as prio tbf htb.

Iii. Specific implementation:

1. Create a SFQ-based throttling algorithm on the NIC


# Tc qdisc add dev eth0 root handle 1: sfq

The SFQ parameter perturb (re-adjusted algorithm interval) quantum basically does not need to be adjusted manually:

Handle 1: Specifies the algorithm number. You do not need to specify the number by the system ..

# Tc qdisc sh dev eth0 display algorithm

# Tc qd del dev eth0 root Delete Note: Default eht0 supports TOS
2. Set the TBF algorithm to throttling on the NIC.
# Tc qd add dev eth1 root handle 1: tbf rate 256 kbit burst 10000 latency 50 ms
256 kbit burst transmission speed: 10 k max latency: 50 ms
# Tc-s qd sh dev eth1 statistics
# Delete tc qd del dev eth1 root
3. Create a PRIO In the NIC
# Tc qdisc add dev eth0 root handle 1: prio
# This command immediately creates classes:, and (three default subclasses)
# Tc qdisc add dev eth0 parent 1:1 handle 10: sfq
# Tc qdisc add dev eth0 parent handle 20: tbf rate 20 kbit buffer 1600 limit 3000
Note: This is another way of writing TBF speed limit.
# Tc qdisc add dev eth0 parent :3 handle 30: sfq
4. the WEB server's traffic is controlled at 5 Mbps, And the SMTP traffic is controlled at 3 Mbps. In addition, the two cannot exceed 6 Mbps, And the borrow bandwidth is allowed between them.
# Tc qdisc add dev eth0 root handle 1:0 cbq bandwidth 100 Mbit avpkt 1000 cell 8
# Tc class add dev eth0 parent 1:0 classid cbq bandwidth 100 Mbit rate 6 Mbit weight
0.6 Mbit prio 8 allot 1514 cell 8 maxburst 20 avpkt 1000 bounded
In this part, the root is set to 1:0 and the class is bound to. That is to say, the bandwidth cannot exceed 6 Mbps.
# Tc class add dev eth0 parent classid cbq bandwidth 100 Mbit rate 5 Mbit weight
0.5 Mbit prio 5 allot 1514 cell 8 maxburst 20 avpkt 1000
# Tc class add dev eth0 parent classid cbq bandwidth 100 Mbit rate 3 Mbit weight
0.3 Mbit prio 5 allot 1514 cell 8 maxburst 20 avpkt 1000
Two classes are created. note how we adjust the weight parameter based on the bandwidth. Neither of the two classes is configured as "bounded", but they are connected.
Received from class, and set "bounded" in class, so the total bandwidth of the two classes will not exceed 6 Mbps. Don't forget, the sub-class under the same CBQ
The primary number of the class must be the same as that of the CBQ!
# Tc qdisc add dev eth0 parent :3 handle 30: sfq
# Tc qdisc add dev eth0 parent :4 handle 40: sfq
By default, both classes have a FIFO queue rule, but we replace it with an SFQ queue to ensure that each data stream is treated fairly.
# Tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip sport 80 0 xffff flowid
1: 3
# Tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip sport 25 0 xffff flowid
1: 4
6. Filter Example
# Tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match ip dport 22 0 xffff flowid 10:1
Add a filter rule to the 10: node. Priority 1: All IP data packets destined for 22 ports (exact match) are sent to channel 10:1 ..
# Tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match ip sport 80 0 xffff flowid 10:1
Add a filter rule to the 10: node. Priority 1: All IP data packets from 80 ports (exact match) are sent to channel 10:1 ..
# Tc filter add dev eth0 protocol ip parent 10: prio 2 flowid 10: 2
10 On eth0: Add a filtering rule to the node. Its priority is 2: Any IP data packets that do not match in the previous sentence are sent to the channel ..
# Tc filter add dev eth0 parent protocol ip prio 1 u32 match ip dst 4.3.2.1/32 flowid 10
The packet destined for 4.3.2.1 is sent to channel 10:1. Other parameters are shown in the preceding example.
# Tc filter add dev eth0 parent protocol ip prio 1 u32 match ip src 1.2.3.4/32 flowid 10
Packets from 1.2.3.4 are sent to channel 10:1
# Tc filter add dev eth0 protocol ip parent 10: prio 2 flowid 10: 2
Any package that does not match the above two sentences will be sent
# Tc filter add dev eth0 parent 10:0 protocol ip prio 1 u32 match ip src 4.3.2.1/32 match
Ip sport 80 0 xffff flowid 10:1
Match can be used continuously to match the 80 packets from Port 1.2.3.4.

This article permanently updates the link address:

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.