测试容器中的网络

容器中的网络延时

部署NetPerf服务
wget http://repo.iotti.biz/CentOS/7/x86_64/netperf-2.7.0-1.el7.lux.x86_64.rpm
rpm -ivh netperf-2.7.0-1.el7.lux.x86_64.rpm
启动服务
netserver

测试主机的网络情况

netperf -t TCP_STREAM -H 10.221.2.191 -t TCP_RR

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@node4 tools]# netperf -t TCP_STREAM -H 10.221.2.191 -t TCP_RR
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.221.2.191 () port 0 AF_INET : first burst 0
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec

16384 87380 1 1 10.00 5862.55
16384 87380
[root@node4 tools]# netperf -t TCP_STREAM -H 10.221.2.191 -t TCP_RR
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.221.2.191 () port 0 AF_INET : first burst 0
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec

16384 87380 1 1 10.00 5411.15
16384 87380
[root@node4 tools]# netperf -t TCP_STREAM -H 10.221.2.191 -t TCP_RR
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.221.2.191 () port 0 AF_INET : first burst 0
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec

16384 87380 1 1 10.00 5995.46
16384 87380

平均 5756.39

测试容器内网络情况

docker run -it –name testNW -v /home/net/:/home/net/ centos:7 /bin/bash
docker cp netperf-2.7.0-1.el7.lux.x86_64.rpm testNW:/home/tools/netperf-2.7.0-1.el7.lux.x86_64.rpm(另外的终端里面执行)
rpm -ivh netperf-2.7.0-1.el7.lux.x86_64.rpm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@ec8fc422533e tools]# netperf -t TCP_STREAM -H 10.221.2.191 -t TCP_RR
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.221.2.191 () port 0 AF_INET : first burst 0
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec

16384 87380 1 1 10.00 5205.07
16384 87380
[root@ec8fc422533e tools]# netperf -t TCP_STREAM -H 10.221.2.191 -t TCP_RR
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.221.2.191 () port 0 AF_INET : first burst 0
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec

16384 87380 1 1 10.00 5263.94
16384 87380
[root@ec8fc422533e tools]# netperf -t TCP_STREAM -H 10.221.2.191 -t TCP_RR
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.221.2.191 () port 0 AF_INET : first burst 0
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec

16384 87380 1 1 10.00 4979.48
16384 87380

平均 5149.50
5149.50 / 5756.39 = 0.895
损失了10% 左右的性能

测试容器内网络情况(共享宿主机网络)

docker run -it –name testNW –network host -v /home/net/:/home/net/ centos:7 /bin/bash

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@node4 tools]# netperf -t TCP_STREAM -H 10.221.2.191 -t TCP_RR
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.221.2.191 () port 0 AF_INET : first burst 0
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec

16384 87380 1 1 10.00 5713.07
16384 87380
[root@node4 tools]# netperf -t TCP_STREAM -H 10.221.2.191 -t TCP_RR
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.221.2.191 () port 0 AF_INET : first burst 0
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec

16384 87380 1 1 10.00 5420.56
16384 87380
[root@node4 tools]# netperf -t TCP_STREAM -H 10.221.2.191 -t TCP_RR
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.221.2.191 () port 0 AF_INET : first burst 0
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec

16384 87380 1 1 10.00 5877.33
16384 87380

平均 5670.32
5670.32 / 5756.39 = 0.985
其网络延迟跟宿主机基本没有差异