MacOS Wifi Latency Spikes Due to Location Service
To avoid Wifi latency/ping spikes every 5 minutes, disable macOS Location Service (Settings -> Security & Privacy -> Privacy -> Location Services) and don't allow "Find my location" in any apps (e.g. Google Chrome).
Like the majority of us these days, I am working from home due to the COVID-19 virus that is spreading worldwide. Working from home means a lot of video-conferencing with Zoom, GotoMeetings, WebEx and Teams. I quickly realized that I had some connectivity issues during my calls when the image would freeze and people would stop talking. I don't usually have these issues at the office...
So three things came to my mind:
- I have a very bad Internet connection at home.
- My ISP is out of capacity and there is congestion on their network.
- I have a Wifi issue since I use an Ethernet cable at the office.
Points 1 and 2 were quite easy to verify since I have an Obkio Hardware Agent X1001 connected to my home network that has monitoring sessions with Public Monitoring Agents installed at AWS, Google Cloud and Microsoft Azure. I was quickly able to confirm that the connection was pretty stable and that I didn't have any jitter, high latency or packet loss during the video calls where I had the image freeze issue.
At this point, I figured that my issue was probably related to my Wifi network, even though my setup is supposed to be pretty strong: Google Wifi with 3 Access Points all wired with Ethernet cables. Anyways, let's dig into the troubleshooting.
On my MacBook Pro 2017 (running macOS Catalina 10.15.3), I installed VirtualBox and started an Obkio Agent with a Virtual Appliance. After only a few minutes, early results were indicating that something was going on for sure! I saw big spikes of latency exactly every 5 minutes. So I compared the graphs of my two local agents (hardware agent (wired) and virtual appliance (wifi)) with the Public Monitoring Agent on AWS. I didn't see the same spikes in latency wired-vs-wifi as you can see in this screenshot:
It was very easy to see the issue with a single ping to the default gateway:
ping -i 0.2 <IP>.
To find out what was causing these Wifi ping spikes, I enabled Wifi Logging (OPTION+Click on the Wifi icon on the menu bar -> Enable Wifi Logging) and then I executed
tail -F /var/log/wifi.log in a terminal. I waited for the issue to come and then I saw that it was the
locationd process that issued a scan request.
The first solution to avoid these latency spikes every 5 minutes is to disable the MacOS Location Service (Settings -> Security & Privacy -> Privacy -> Location Services).
Once in a while, I authorize some websites inside Google Chrome to know my location (e.g. Google Maps). When you visit these websites, it can trigger a location scan and cause the same issue. Finding out if an application is requesting a wifi scan is very easy; simply look at the Wifi logs (/var/log/wifi.log) mentioned above.
By clicking on the Wifi icon on the menu bar with the OPTION key pressed, an advanced menu will display stats about current Wifi connection such as signal strength (RSSI), noise level, current BSSID, and wifi channel. When I have wifi issues, I like to take a look at these stats to know, for instance, if I am connected using a 2.4GHz or a 5GHz frequency. However, every time you do that, it triggers a wifi scan that is even deeper than the location service scan and results in a few seconds of packet loss and higher latency spikes. So don't do this during video calls, you are actually making the situation worse.
Looks like I am not the only one with this issue: https://forums.developer.apple.com/thread/97805. Apple is aware of the issue since at least 2018 but I still have the issue with the latest MacOS Catalina 10.15.3. It might be a hardware limitation, I don't know, but I hope it will get fixed in the near future.
If you want to discuss this issue, join the discussion on our Forums at https://forums.obkio.com.