sparkfabrik / sparkdock

Automatic MacOS system provisioning
19 stars 8 forks source link

Docker for mac performance tuning #61

Open paolomainardi opened 1 year ago

paolomainardi commented 1 year ago

Context

We all know that Docker performance on mac for some cases is quite limited in terms of filesystem performance, mainly caused by the shared network disk between the host and the docker for mac VM.

There is a long-standing issue you can find here: https://github.com/docker/roadmap/issues/7

We as a company invested a lot in the past to reach close-native performance between Linux and macOS, in the docker-machine era we used NFS sharing which leads to very close native performance, then we decided to mainly use Linux for our developer workstations also to avoid this kind of performance issues.

With the Apple Silicon era, we decided to invest again in macOS for our developer workstations, as the machines are powerful, cheap and with the best-in-class hardware you can find on the market now.

The current Docker for Mac improved a lot the filesystem sharing issues, but it still falls behind the native performance, especially with heavy fs scenarios usage like Node and PHP with node_modules and vendor directories which can become very very big also in simple projects.

Benchmark

Repository: https://github.com/paolomainardi/docker-for-mac-bench

I am going to use create-react-app as a use case scenario, the test is executed:

  1. Empty node_modules
  2. NPM cache

Filesystem

Native

❯ time npm install

real 6.12s 

Doker for mac - gRPC Fuse (default)

❯ time npm install

real 56.835s

Docker for mac - Virtiofs (beta)

root@f546acf5bf5b:/usr/src/app# time npm install

real    18.864s

CPU

❯ make test-cpu
time node cpu-bench.js
        4.08 real         4.01 user         0.06 sys
docker run --rm -it -v $PWD:/usr/src/app -v $PWD/.cache:/root/.npm -w /usr/src/app node:18-slim bash -c "time node cpu-bench.js"

real    0m4.138s
user    0m4.104s
sys     0m0.024s

macOS 13

❯ make test-native test-docker-nomount test-docker-nodemodule-mount test-docker-mount
Testing: Native installation...

real 4.66

Testing: Docker without volume mount...

real    0m 7.23s

Testing: Docker with node_modules mounted as a named volume...

real    0m 6.97s

Testing: Docker with volume mount...

real    0m 17.15s
paolomainardi commented 1 year ago

Ref: https://github.com/docker/for-mac/issues/6590

paolomainardi commented 1 year ago

Devcontainers info:

paolomainardi commented 1 year ago

Ref: https://github.com/docker/roadmap/issues/7

paolomainardi commented 1 year ago

Another test with:

  1. Ventura 13.1
  2. Docker Desktop 4.15.0
➜  bench-macos git:(main) make
Testing: Native installation...

real 4.02

Testing: Docker without volumes...

real    0m 6.56s

Testing: Docker with a bind mount: './create/react/app:/usr/src/app' and a volume on: 'nodemodules:/usr/src/app/node_modules'

real    0m 7.04s

Testing: Docker with a bind mount: ./create-react-app:/usr/src/app

real    0m 21.86s