Docker the configuration of network resource restriction

Source: Internet
Author: User
Tags rsync openvswitch

One, the following is my test results:

For the speed limit of 100m below, in fact, the type of hard disk and read and write speed has no effect, but how to limit the speed of more than 150m, or infinite speed, then the hard drive is definitely ssd>sas>sata, so it is recommended to use the SAS disk as a Docker mount partition.
Openvswitch The default official document provides a speed limit method "rate limiting VM traffic using QoS policing", address is http://openvswitch.org/support/ config-cookbooks/qos-rate-limiting/, this speed limit can only upload speed limit, download no way, so you have to use other QoS to do the restrictions.

Two, the following is the specific speed limit script


#!/bin/bash
#filename: modify_docker_container_network_limit.sh
#author:D Eng Lei
#email:d l528888@gmail.com
Op=$1
Container=$2
Limit=$3 # MBITS/S
If [-Z $] | | [-Z $]; Then
echo "Usage:operation container_name limit (default:5m)"
echo "Example1:i want limit 5m in the Container:test"
echo "The command Is:bash ' basename $ ' limit test 5"
echo "Example2:i want delete network limit in the Container:test"
echo "The command Is:bash ' basename $ ' ulimit test"
Exit 1
Fi
If [-Z $];then
limit= ' 5m '
Fi
If [' Docker inspect--format ' {{. State.pid}} "$container &>>/dev/null && echo 0 | | Echo 1 '-eq 1];then
echo "No this container: $container"
Exit 1
Fi
ovs_prefix= ' VETH1PL '
Container_id= ' Docker inspect--format ' {{. State.pid}} "$container"
Device_name= ' echo ${ovs_prefix}${container_id} '
if [$op = = ' Limit '];then
For V in $device _name; Todo
Ovs-vsctl set Interface $v ingress_policing_rate=$ ((limit*1000))
Ovs-vsctl set Interface $v ingress_policing_burst=$ ((limit*100))
Ovs-vsctl set port $v qos= @newqos----id= @newqos create QoS TYPE=LINUX-HTB queues=0= @q0 other-config:max-rate=$ (limit*1 000000)----id= @q0 Create queue other-config:min-rate=$ ((limit*1000000)) other-config:max-rate=$ ((limit*1000000)) &>>/dev/null && Echo ' modify success! ' | | Echo ' Modify fail! '
Done
elif [$op = = ' Ulimit '];then
For V in $device _name; Todo
Ovs-vsctl set interface $v ingress_policing_rate=0
Ovs-vsctl set interface $v ingress_policing_burst=0
Ovs-vsctl Clear Port $v QoS &>>/dev/null && Echo ' modify success! ' | | Echo ' Modify fail! '
Done
Fi
This script is used, the speed limit can be directly targeted to download and upload, and the restrictions are unified effective, such as I limit a container bandwidth of 5m, then download and upload the speed limit is 5m, the unit is bit is not byte.

Three, the following is the use of the method:


[Root@docker-test3 tmp]# SH modify_docker_container_network_limit.sh
Usage:operation container_name Limit (default:5m)
Example1:i want limit 5m in the Container:test
The command is:bash modify_docker_container_network_limit.sh limit test 5
EXAMPLE2:I want delete network limit in the Container:test
The command is:bash modify_docker_container_network_limit.sh ulimit test
Four, the following is the test process:

The test method is:

Find another host 172.16.1.126, then DD generates a 100m file/tmp/test_client.iso, download this file to test download speed, and generate 100m files in native DD/tmp/test_ Server.iso uploaded this file to the 172.16.1.126 test upload speed.
SATA 7.5k

1, no restrictions on the situation

Download speed


14:12:18 # Rsync-avz--progress 172.16.1.126:/tmp/test_client.iso/tmp/
root@172.16.1.126 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 56.82mb/s 0:00:01 (xfer#1, TO-CHECK=0/1)

Sent bytes received104892888 bytes 1226817.75 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


14:14:27 # Rsync-avz--progress/tmp/test_server.iso172.16.1.126:/tmp/
root@172.16.1.126 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 51.08mb/s 0:00:01 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes received31 bytes 29969404.00
Total size is 104857600 speedup is 1.00

2, speed limit of 5m

Download speed


14:15:27 # Rsync-avz--progress 172.16.1.126:/tmp/test_client.iso/tmp/
root@172.16.1.126 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 580.46kb/s 0:02:56 (xfer#1, TO-CHECK=0/1)

Sent bytes received104892888 bytes 590946.02 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


14:22:10 # Rsync-avz--progress/tmp/test_server.iso172.16.1.126:/tmp/
root@172.16.1.126 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 616.19kb/s 0:02:46 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes received31 bytes 571623.51
Total size is 104857600 speedup is 1.00

3, speed limit of 10m

Download speed


14:28:55 # Rsync-avz--progress 172.16.1.126:/tmp/test_client.iso/tmp/
root@172.16.1.126 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 1.13mb/s 0:01:28 (xfer#1, TO-CHECK=0/1)

Sent bytes received 104892888bytes 1109977.97 bytes/sec
Total size is 104857600 speedup is 1.00
Root@fdc81b0d2508:/tmp

Upload speed


14:30:33 # Rsync-avz--progress/tmp/test_server.iso172.16.1.126:/tmp/
root@172.16.1.126 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 1.21mb/s 0:01:22 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes received31 bytes 1133977.45
Total size is 104857600 speedup is 1.00

4, speed limit of 20m

Download speed


14:32:57 # Rsync-avz--progress 172.16.1.126:/tmp/test_client.iso/tmp/
root@172.16.1.126 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 2.27mb/s 0:00:44 (xfer#1, TO-CHECK=0/1)

Sent bytes received104892888 bytes 2305338.86 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


14:33:59 # Rsync-avz--progress/tmp/test_server.iso172.16.1.126:/tmp/
root@172.16.1.126 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 2.45mb/s 0:00:40 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes received31 bytes 2305338.77
Total size is 104857600 speedup is 1.00

5, speed limit of 50m

Download speed


14:35:20 # Rsync-avz--progress 172.16.1.126:/tmp/test_client.iso/tmp/
root@172.16.1.126 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 5.67mb/s 0:00:17 (xfer#1, TO-CHECK=0/1)

Sent bytes received 104892888bytes 5379124.00 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


14:35:54 # Rsync-avz--progress/tmp/test_server.iso172.16.1.126:/tmp/
root@172.16.1.126 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 6.33mb/s 0:00:15 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes received31 bytes 5116727.51
Total size is 104857600 speedup is 1.00

6, speed limit 100m

Download speed


14:37:18 # Rsync-avz--progress 172.16.1.126:/tmp/test_client.iso/tmp/
root@172.16.1.126 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 11.35mb/s 0:00:08 (xfer#1, TO-CHECK=0/1)

Sent bytes received104892888 bytes 8391433.44 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


14:37:39 # Rsync-avz--progress/tmp/test_server.iso172.16.1.126:/tmp/
root@172.16.1.126 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 13.19mb/s 0:00:07 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes received31 bytes 11041359.37
Total size is 104857600 speedup is 1.00

7, speed limit 150m

Download speed


14:38:39 # Rsync-avz--progress 172.16.1.126:/tmp/test_client.iso/tmp/
root@172.16.1.126 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 11.35mb/s 0:00:08 (xfer#1, TO-CHECK=0/1)

Sent bytes received 104892888bytes 11041359.79 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


14:38:56 # Rsync-avz--progress/tmp/test_server.iso172.16.1.126:/tmp/
root@172.16.1.126 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 13.14mb/s 0:00:07 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes received31 bytes 11041359.37
Total size is 104857600 speedup is 1.00

The following is a test result using the SAS 7.5k hard drive

8, infinite speed of

Download speed


17:11:07 # Rsync-avz--progress172.16.1.53:/tmp/test_client.iso/tmp/
root@172.16.1.53 ' s Password:
Receiving incremental file list
Test_client.iso
2147483648 100% 106.42mb/s 0:00:19 (xfer#1, TO-CHECK=0/1)

Sent bytes received 2148204633 bytes 95475762.80 bytes/sec
Total size is 2147483648 speedup is 1.00

Upload speed


17:20:06 # Rsync-avz--progress/tmp/test_server.iso 172.16.1.53:/tmp/
root@172.16.1.53 ' s Password:
Sending incremental file list
Test_server.iso
2147483648 100% 112.51mb/s 0:00:18 (xfer#1, TO-CHECK=0/1)

Sent 2148204628 bytes Received bytes 95475762.62
Total size is 2147483648 speedup is 1.00

9, 5m speed limit

Download speed


17:30:30 # Rsync-avz--progress172.16.1.53:/tmp/test_client.iso/tmp/
root@172.16.1.53 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 591.44kb/s 0:02:53 (xfer#1, TO-CHECK=0/1)

Sent bytes received 104892888 bytes 587635.39 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


17:38:57 # Rsync-avz--progress/tmp/test_server.iso 172.16.1.53:/tmp/
root@172.16.1.53 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 590.35kb/s 0:02:53 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes Received bytes 574755.69
Total size is 104857600 speedup is 1.00
10, speed limit 10m

Download speed


17:42:54 # Rsync-avz--progress172.16.1.53:/tmp/test_client.iso/tmp/
root@172.16.1.53 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 1.15mb/s 0:01:26 (xfer#1, TO-CHECK=0/1)

Sent bytes received 104892888 bytes 1146370.69 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


17:44:31 # Rsync-avz--progress/tmp/test_server.iso 172.16.1.53:/tmp/
root@172.16.1.53 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 1.16mb/s 0:01:26 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes Received bytes 1146370.64
Total size is 104857600 speedup is 1.00
11, speed limit 20m

Download speed


17:47:02 # Rsync-avz--progress172.16.1.53:/tmp/test_client.iso/tmp/
root@172.16.1.53 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 2.32mb/s 0:00:43 (xfer#1, TO-CHECK=0/1)

Sent bytes received 104892888 bytes 2162740.58 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


17:48:06 # Rsync-avz--progress/tmp/test_server.iso 172.16.1.53:/tmp/
root@172.16.1.53 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 2.38mb/s 0:00:42 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes Received bytes 2255761.59
Total size is 104857600 speedup is 1.00
12, speed limit 50m

Download speed


17:52:52 # Rsync-avz--progress172.16.1.53:/tmp/test_client.iso/tmp/
root@172.16.1.53 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 5.84mb/s 0:00:17 (xfer#1, TO-CHECK=0/1)

Sent bytes received 104892888 bytes 5116727.71 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


17:53:15 # Rsync-avz--progress/tmp/test_server.iso 172.16.1.53:/tmp/
root@172.16.1.53 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 6.10mb/s 0:00:16 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes Received bytes 5993880.80
Total size is 104857600 speedup is 1.00
13, speed limit of 100m

Download speed


17:55:16 # Rsync-avz--progress172.16.1.53:/tmp/test_client.iso/tmp/
root@172.16.1.53 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 11.75mb/s 0:00:08 (xfer#1, TO-CHECK=0/1)

Sent bytes received 104892888 bytes 9989801.71 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed


17:55:39 # Rsync-avz--progress/tmp/test_server.iso 172.16.1.53:/tmp/
root@172.16.1.53 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 12.72mb/s 0:00:07 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes Received bytes 11041359.37
Total size is 104857600 speedup is 1.00
14, speed limit 150m

Download speed


17:56:58 # Rsync-avz--progress 172.16.1.53:/tmp/test_client.iso/tmp/
root@172.16.1.53 ' s Password:
Receiving incremental file list
Test_client.iso
104857600 100% 17.69mb/s 0:00:05 (xfer#1, TO-CHECK=0/1)

Sent bytes received 104892888 bytes 13985722.40 bytes/sec
Total size is 104857600 speedup is 1.00

Upload speed

17:57:18 # Rsync-avz--progress/tmp/test_server.iso 172.16.1.53:/tmp/
root@172.16.1.53 ' s Password:
Sending incremental file list
Test_server.iso
104857600 100% 20.44mb/s 0:00:04 (xfer#1, TO-CHECK=0/1)

Sent 104892883 bytes Received bytes 16137371.38
Total size is 104857600 speedup is 1.00
If you have any questions you can leave a message to me, I will reply in time.

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.