I'm having a very weird behavior. I have a web app that makes an http request to an external API endpoint. This is taking extremely long, around 5 - 30 seconds when it's done or the first time. (On average, it's around 15 seconds.)
I'm currently on a fresh install of PopOS 20.04 which is basically Ubuntu 20.04, but the problem still exists. (EDIT: I have also tried this on Ubuntu 20.04 and have the same issue.) This is not a VPS. It's my laptop.
Here is what I noticed:
- The request is slow for the first time and subsequent requests are extremely fast. After a few minutes, the request becomes slow again, but only the first one.
- I don't any issues browsing websites on my browser. It's fast.
- I don't have this issue on Ubuntu 18.04.
- I tried using curl from Terminal to make the API request to simplify the scenario. This is significantly better, but still takes around 3 - 5 seconds on average. The same using Invoke-WebRequest from PowerShell on Windows is extremely fast (avg 300-400ms).
- When I connect to a hotspot created by iPhone, the request is extremely fast. It's slow on my home wifi. I tried this on a public network at my local library yesterday and it was also very slow. (This is biggest clue I have so far.)
My home wifi and the hotspot shared from my iPhone have around the same speed.
I have no idea why this happens. Any help is greatly appreciated.