Very slow network performance of Docker containers with host's network

Truong picture Truong · Jul 25, 2016 · Viewed 14.6k times · Source

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?

Answer

Santanu Dey picture Santanu Dey · Jul 25, 2016

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.

  1. 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
  2. Then you might want to modify various resource allocation parameters available with docker run. enter image description here

    1. 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