What a great question -- I'd honestly never considered the network speed difference between WSL1 and WSL2 before, nor really had the need personally.
The answer, apparently, is yes, an SSH connection over WSL2 appears to be be much faster than the same in WSL1.
To test, I installed pv
in a WSL1 and WSL2 instance and:
yes | pv | ssh $host "cat > /dev/null"
With the host being a hosted virtual server.
- WSL1 was around 34MiB/s, best case, but dipped to 27MiB/s at points
- WSL2 ran a steady 110-111MiB/s
I repeated the tests again on a freshly installed (and updated
/upgraded
) Ubuntu 20.04 instance, doing a wsl --set-version Ubuntu 1
after the WSL2 test.
The results there were pretty much the same, but stayed at around 27MiB/s for WSL1. WSL2 was still right at 111MiB/s.
Just for fun (not a valid comparison), I ran:
yes | pv | pwsh.exe -c "ssh $host 'cat > /dev/null'"
To push the traffic through PowerShell to the Windows SSH client. That, of course, has to cross the process boundary between Windows and WSL on each call, so there's a lot more overhead. The results there were:
- About 20MiB/s on WSL1
- About 17MiB/s on WSL2
That's not surprising since WSL1 runs closer to the Windows API than WSL2.
I'm actually a bit surprised at the primary difference between WSL1 and WSl2. I was honestly expecting WSL1 to have the performance advantage, since it shares the network with Windows rather than being NAT'd behind a virtualized interface and switch.