带有主机网络的Docker容器的网络性能非常慢 [英] Very slow network performance of Docker containers with host's network
问题描述
我在Docker容器和主机网络之间的网络性能缓慢方面遇到了问题.我在Docker论坛上问了这个问题,但到目前为止还没有收到答案.
问题
设置:同一本地网络上的两台Mac;第一个运行MQTT经纪人(mosquitto);第二个运行Docker for Mac.两个C ++程序在第二台Mac上运行,并使用Paho MQTT C库通过MQTT代理(在第一台Mac上)多次交换数据.
本机运行:当我本地运行两个C ++程序时,网络性能达到了预期的出色.这些程序是使用XCode 7.3构建的.
Docker运行:当我在Docker中运行一个或两个C ++程序时,网络性能急剧下降,大约比本机运行慢30倍. Docker镜像基于ubuntu:latest,程序由gcc(Ubuntu 5.4.0-6ubuntu1〜16.04.1)5.4.0 20160609构建.
我尝试使用主机网络(在Docker运行中为--network ="host"),但没有帮助.我还尝试在第二台Mac上运行MQTT代理(以便该代理和容器在同一主机上运行).问题仍然存在.我的工作局域网和家庭网络都存在该问题.
理论上,可能是Docker容器中的C ++程序通常运行缓慢.但是我怀疑是这种情况,因为根据我的经验,Docker中C ++代码的一般性能与在本机环境中一样快.
问题
此问题可能是什么原因? Docker中有什么设置可以解决此问题?
我怀疑容器的默认内存和CPU分配可能不是您要达到的那种网络性能的最佳选择.- 使用top,htop,strace等标准工具调查容器内资源的利用率.或者,当这些实例处于高峰运行状态时,可以使用docker stat命令
$ docker stats node1 node2 CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O node1 0.07% 796 KB/64 MB 1.21% 788 B/648 B node2 0.07% 2.746 MB/64 MB 4.29% 1.266 KB/648 B
-
然后,您可能想要修改docker run可用的各种资源分配参数.
- 要检查的另一件事是实际系统接口的MTU和docker接口上的设置.使用
--mtu=BYTES
设置docker值的MTU以匹配系统界面的MTU值
- 要检查的另一件事是实际系统接口的MTU和docker接口上的设置.使用
I'm having a problem with sluggish network performance between Docker containers and host's network. I asked this question on the Docker's forum but have received no answers so far.
Problem
Set-up: two Macs on the same local network; the first runs an MQTT broker (mosquitto); the second runs Docker for Mac. Two C++ programs run on the second Mac and exchange data multiple times through the MQTT broker (on the first Mac), using the Paho MQTT C library.
Native run: when I ran the two C++ programs natively, the network performance was excellent as expected. The programs were built with XCode 7.3.
Docker runs: when I ran either of the C++ programs, or both of them, in Docker, the network performance dropped dramatically, roughly 30 times slower than the native run. The Docker image is based on ubuntu:latest, and the programs were built by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609.
I tried to use the host network (--network="host" in Docker run) but it didn't help. I also tried to run the MQTT broker on the second Mac (so that the broker and the containers ran on the same host); the problem persisted. The problem existed on both my work LAN and my home network.
In theory, it could have been that the C++ programs were generally slow in Docker containers. But I doubt this was the case because in my experience, the general performance of C++ code in Docker is about as fast as in the native environment.
Question
What could be the cause of this problem? Are there any settings in Docker that can solve this issue?
I suspect the default allocation of memory and CPU for the containers might not be optimal for the kind of network performance you are trying to achieve.
- Investigate the utilization of resources within the containers using standard tools like top, htop, strace etc. Or you can use docker stat command when these instances are in peak operation
$ docker stats node1 node2 CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O node1 0.07% 796 KB/64 MB 1.21% 788 B/648 B node2 0.07% 2.746 MB/64 MB 4.29% 1.266 KB/648 B
Then you might want to modify various resource allocation parameters available with docker run.
- EDIT: Another thing to check would be MTU of the actual system interface and the setting on the docker interfaces. Use
--mtu=BYTES
to set MTU of your docker values to match your system interface's MTU value
- EDIT: Another thing to check would be MTU of the actual system interface and the setting on the docker interfaces. Use
这篇关于带有主机网络的Docker容器的网络性能非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!