docker / for-win

Bug reports for Docker Desktop for Windows
https://www.docker.com/products/docker#/windows
1.86k stars 291 forks source link

Inefficient collection of WSL resource utilisation data (high process spawn rate) #13080

Open ralish opened 1 year ago

ralish commented 1 year ago

Actual behavior

Docker Desktop spawns a very high number of processes during operation, including while in the background with no user containers running. These processes appear to be for the purpose of collecting resource usage data from the WSL environment.

Sampling over a 1 minute interval, Docker Desktop spawns 36 wsl.exe processes, each of which in turn spawn 3 additional processes, for a total of 144 processes. Extrapolating to an hour, that means Docker Desktop is spawning 8,640 processes just to collect resource usage information. The true number is higher, as there are other apparent processes spawned for similar purposes (e.g. powershell.exe) but they are far less frequent in frequency.

The wsl.exe command is being spawned with two specific invocations:

For each of these invocations, another three processes are spawned so that the process tree looks like this:

com.docker.backend.exe
|- C:\Windows\System32\wsl.exe -d docker-desktop cat <one-of-the-above-files>
 |- C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\wsl.exe -d docker-desktop cat <one-of-the-above-files>
  |- C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\wslhost.exe --mode 4 --distro-id {<some-guid>} --vm-id {<some-guid>} --handle <handle-id> --event <event-id> --parent <parent-pid>
   |- \??\C:\Windows\system32\conhost.exe 0xffffffff -ForceV1

The second invocation of wsl.exe under WindowsApps is I expect due to this system using the newer Windows Store based WSL. If you're using the inbox WSL included with Windows, this probably doesn't spawn and the initial wsl.exe under System32 presumably just launches wslhost.exe directly (except under C:\Windows\System32\lxss\wslhost.exe). So each wsl.exe invocation is slightly more efficient, with only two child processes spawned instead of three.

Expected behavior

Docker Desktop should take a more efficient approach to collecting resource usage data from WSL that isn't so resource intensive. Process creation under Windows is generally much more "expensive" than under Unix-like platforms. While recent Windows releases have made improvements, it's still not at all comparable in performance to Unix-like systems. The impact of constantly spawning so many processes is sure to be material, and it's especially sub-optimal given this is while Docker Desktop is simply in the background with no user containers running (i.e. it should be effectively "idle").

Information

The problem should be reproducible on any system with WSL installed and using the WSL 2 backend. I'm not clear if Docker supports WSL 1, and if it does, I haven't tested it. Using the latest WSL release from the Windows Store will further exacerbate the issue, but it's present using the inbox WSL shipped with Windows itself.

Output of & "C:\Program Files\Docker\Docker\resources\com.docker.diagnose.exe" check

Steps to reproduce the behavior

  1. Install Docker Desktop on a Windows system with WSL 2
  2. Use a performance monitoring tool to observe Docker Desktop's frequent spawning of wsl.exe processes (e.g. Process Monitor)
ralish commented 1 year ago

One thought: a simple way to fix this may be to just access the required files over the Plan 9 network filesystem? For example, read from \\wsl$\docker-desktop\proc\meminfo. This can be done directly from within the com.docker.backend.exe process.

AronRubin commented 1 year ago

I am also experiencing this

docker-robott commented 1 year ago

There hasn't been any activity on this issue for a long time. If the problem is still relevant, mark the issue as fresh with a /remove-lifecycle stale comment. If not, this issue will be closed in 30 days.

Prevent issues from auto-closing with a /lifecycle frozen comment.

/lifecycle stale

ralish commented 1 year ago

Still definitely an issue. Most recently tested on Docker Desktop v4.17.0.

/remove-lifecycle stale /lifecycle frozen

egonelbre commented 1 year ago

Just noticed this problem as well. Still an issue on Docker 4.17.1.

mc-alt commented 1 year ago

I am experiencing this issue as well

ralish commented 1 year ago

Bumping this as it feels like an easy win relative to the performance benefit. Would be nice to get at least some comment from the Docker Desktop team.

qc00 commented 1 year ago

My environment has some security software that uses a lot of CPU whenever a process is created, so Docker Desktop is making the fan scream.

There are much better ways to get such basic metrics as opposed to shelling processes in a loop...

rasmusmk commented 1 year ago

I am seeing the same issue using wsl image created with podman