Switching to 5Ghz wifi made the Raspberry Pi fly again

For the last few months my Raspberry Pi 4 was happily running on my desk, tucked away next to the monitor. It's serving a small web app in golang on the internal network and tailscale. I've never noticed any latency problems with it, so it took me by surprise when I deployed some OCaml experiments on the Pi and observed a lot of HTTP connection timeouts and name resolution errors while fetching some URLs concurrently.

Since I cross compiled the experiment from my M1, I first thought there might by some issues related to the TLS setup in Cohttp. So I've copied the source files over ssh and installed all dependencies via opam. Average download speed of 0.5 Mbit/s. WTF? Some unrelated git clone showed the same speed and just timed out...

Running uptime showed 120 days, so I blamed it on some obscure wifi stack issue and did what most people would:

It did not disappoint: download speed was back to 80 Mbit/s and no connection errors while fetching the URLs. Problem solved.

Or so I thought. The next day the same thing happened again. How is this possible? While searching the Raspberry pi forum two things caught my eye: USB3 is interfering with 2.4Ghz wifi and extremly slow wifi on pi4. Both reported slow wifi speeds on 2.4Ghz, which went away after switching to 5Ghz.

And then it dawned on me. I'm running our network on both frequencies under the same name. The day before, when I rebooted the Pi the wifi did not connect automatically, so I temporarily plugged the Pi into my monitor and selected the wifi via the GUI. Which showed 5GHz in the tooltip. Could this have changed? Using nmcli the current network was indeed listed as 2.4Ghz.

$ nmcli -f IN-USE,SSID,BSSID,FREQ device wifi list
IN-USE  SSID       BSSID              FREQ
*       xxxxxxxxx  yy:yy:yy:yy:yy:yy  2412 MHz
        xxxxxxxxx  zz:zz:zz:zz:zz:zz  5200 MHz

Changing the network via

$ sudo nmcli device wifi connect zz:zz:zz:zz:zz:zz password <pw>

had the desired effect and the download speed is back to normal. We can make this permanent by adding band=a in the [wifi] section of /etc/NetworkManager/system-connections/preconfigured.nmconnection and/or <SSID>.nmconnection in the same folder.

I still not sure what exactly the issue with the 2.4GHz network is, especially given that this didn't seem to have happened in the past. Potentially some interference due to the ceiling between the Pi and the router, the fancy metal enclosure I got or a smaller wifi antenna in the Pi. But it doesn't really matter, since it's been working fine for the last few days, and once the brand new network cable arrives, the Pi will be plugged directly into the router.