CGROUP+TC bandwidth throttling for a single process

Source: Internet
Author: User
Tags mysql import


Yesterday there was a need to have a bandwidth limit on a process, learning CGROUP+TC


The approximate process is as follows


First, TC.

TC the approximate process is as follows: Root is qdisc---category that is, root there will be a lot of classification we call him class, which defines the rules, that is, the bandwidth limit of how much----filter which is used to specify which category


Cgroup

Understanding as a container, doing system resource control


    1. Yum Install Libcgroup

2. Mount-t cgroup net_cls -o net_cls /cgroup/net_cls/



#!/bin/bash

#这个脚本是tc与cgroup结合来限制一个进程的流量


#注意: Before executing this script, please make sure that this machine is not deployed TC flow control before

#或者之前部署的流量控制已经不用了.

#这个脚本会先清空之前部署的流量控制, and then execute the commands in the script.


#这个脚本需要传入两个参数

#参数一是设备标记, that's the process, which is the card that goes out

#参数二是流量限制的大小, Unit Mbps, M/s


#执行这个脚本之前应该先对cgroup进行配置, the configuration process is as follows:

#1. Make sure the Cgroup is turned on.

#2. Add a hierarchy group to the subsystem Net_cls, as follows:

# cd/cgroup/net_cls/

# mkdir Group

#3. Write the classid of the queue to the Net_cls.classid file in the group layer, as follows:

# Cd/cgroup/net_cls/group

# echo 0x00010002>net_cls.classid

# The 0x00010002 here means that ClassID is 1:2.

# If you want to change to 1:3, you can: Echo 0x00010003>net_cls.classid

# The ClassID here are classified as below ClassID

#4. To put the process into Cgroup, here is an example of MySQL import:

# cgexec-g Net_cls:group mysqlimport--lock-tables=false-c-H ip-p 3306-u Root-pmima--default-character-set=ut F8-f-R--local inputtest--fiel

Ds-optionally-enclosed-by= "\" "--fields-terminated-by=", '--lines-terminated-by= "\ r \ n" test.csv


If [$#-lt 2]; Then

echo "Parameter Error"

echo "./trffic_limit_cgroup.sh Dev Limit"

Exit

Fi


Dev=$1

Limit=$2


TC Qdisc del Dev $DEV root


TC Qdisc Add dev $DEV root handle 1:HTB

TC class Add dev $DEV parent 1:classid 1:htb rate 1000mbit ceil 1000mbit

TC class Add dev $DEV parent 1:classid 1:2 HTB rate ${limit}mbit


TC Filter Add dev $DEV protocol IP parent 1:0 prio 1 handle 1:2 Cgroup




How to test


Install IPERF Network Quality test

Http://linux.chinaunix.net/techdoc/system/2008/07/03/1014733.shtml


Use Iperf as server and Test side

Service-Side Iperf-s

Execute dstat on client and open an interface to execute cgexec-g net_cls:group iperf-c IP

This article is from the "Expect batch Sync data" blog, so be sure to keep this source http://4249964.blog.51cto.com/4239964/1563868

CGROUP+TC bandwidth throttling for a single process

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.