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

9
  • 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). Commented Aug 22, 2016 at 22:52
  • Sorry! I totally mistiped the results. I was talking about seconds, not millis. Thanks for the quick answer @PeterCordes ! Commented Aug 22, 2016 at 23:01
  • 1
    stackoverflow.com/q/20123823/17034 Commented Aug 22, 2016 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. Commented Aug 22, 2016 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. Commented Aug 22, 2016 at 23:31

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

Comments

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.

4 Comments

Docker for Mac nor Docker for Windows run in VirtualBox. Both run in hypervisors
With the new 1.12, you are correct. I mentioned VirtualBox since the OP mentioned docker-machine.
Based on the comment, I just installed Docker that was posted a few hours ago, one would hope the lastest version is used (which is branded as a native app, so you can remove the "yet")
Yes, I'm on the latest version! :-)
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.

1 Comment

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 :·)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.