13

We just wrote a CPU intensive application to benchmark Docker images. It's a Java application that approximates the decimals of Pi.

  • If we run java -jar superpi.jar it stresses all the cores and takes 30 seconds
  • If we run docker run fewlaps/superpi it stresses only two of the four cores and takes 70 seconds

The Docker image is running the .jar as we do when running it on the host. Why is the Docker image not as fast as running the .jar locally? We expected some difference between running it locally and running it on Docker, but the process takes double the time.

Is there any way to request that Docker use all the CPU?

BTW, the project is published here on GitHub: Fewlaps/SuperPI

Richie Marquez
  • 2,228
  • 3
  • 19
  • 18
Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
  • 1
    30ms is a pretty short time for something as heavy as JVM startup / JIT-compiling. How do the results scale with the run-time of your benchmark? (This would let you estimate the start-up overhead before your benchmark reaches a steady state of running as fast as it's going to in either case). – Peter Cordes Aug 22 '16 at 22:52
  • Sorry! I totally mistiped the results. I was talking about seconds, not millis. Thanks for the quick answer @PeterCordes ! – Roc Boronat Aug 22 '16 at 23:01
  • 1
    http://stackoverflow.com/q/20123823/17034 – Hans Passant Aug 22 '16 at 23:16
  • That's a useful link from Hans. One more thing I didn't think to ask, if you're using a virtual machine to run Docker images. If you are, the VM configuration controls the maximum number of CPU cores. – Zan Lynx Aug 22 '16 at 23:25
  • Nope, I just installed Docker, and it didn't asked for any VM software. It seems that it is managed by Docker itself. Right now I'm reading the documentation of creating a docker-machine on virtualbox. Probably there I can create a docker-machine without any CPU limit. – Roc Boronat Aug 22 '16 at 23:31
  • To rephrase Zan's question, what OS does your host run, did you install on Windows or MacOS, or directly on a Linux system. And where did you run the java command from, was that on the same Linux server? – BMitch Aug 22 '16 at 23:54
  • @BMitch hi! Two are MacOS, and the other one is a Windows. I can try on some VPS that I own to see the results :-) – Roc Boronat Aug 23 '16 at 00:36
  • You don't need Docker Machine anymore with Docker for Mac – OneCricketeer Aug 23 '16 at 01:13
  • Great, thanks for clarificating it, @cricket_007 ! :·) – Roc Boronat Aug 23 '16 at 08:42

3 Answers3

12

Friends, I'm full of shame: the own MacOS Docker desktop client has a setting to enable more or less cores. Don't know if it's something added in the last version, but I didn't notice. By default, it gets two cores instead of four, which seems savvy.

Here's how the screen appears:

enter image description here

By the way, only for the information, on the same machine:

  • Running the .jar takes 64,973 millis
  • Running the Docker image that runs the .jar takes 83,449 millis
Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
6

The Docker for MacOS and Docker for Windows is where your issues are appearing. Docker doesn't run natively on either of these platforms (yet), so the installers for them spin up a VM running boot2docker. These VM's are controlled by VirtualBox and have limits on the numbers of CPU's assigned to the VM. These limits can be adjusted, so I'd start there (review your VirtualBox configuration for Docker instance, changing this will likely require a restart of the VM).

To get a proper comparison of the overhead from containers, you'd want to run your "outside the container" test inside the VM that's running your Docker host. That, or install Docker on a machine that's running Linux on the physical machine, rather than inside of a VM.

BMitch
  • 231,797
  • 42
  • 475
  • 450
3

There are a lot of Docker command line flags related to CPU sets and CPU shares. Make sure that those aren't being set, or specified by default. Once your container is running you can find it with docker ps and see the settings with something like docker inspect gloomy_archimedes and look under the HostConfig section for things like CpuShares, CpusetCpus, etc.

It is also possible that your Docker daemon itself has been limited by its init script or systemd unit definition. You can check that by finding your Docker daemon's PID and cat /proc/1199/status. Look for Cpus_allowed: Should be set to ff.

Or if you are running Docker on Windows or Apple OS X, then Docker will need to use a virtual machine. As far as I know, all Docker images are expecting a Linux operating system environment (although I suppose it is possible someone is building Windows images which would need a VM to run on Linux). That virtual machine will have a configured number of CPU cores. You'll need to find a way to adjust that and make sure it is what you want.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131
  • Great! I will take a look! It's something strange 'cause I'm new to Docker and the three computers where I installed Docker have fresh installs. But I'm happy to read that is not something normal. Thanks for your answer! I will note you when I checked it :·) – Roc Boronat Aug 22 '16 at 23:22