Score:-3

Ubuntu 20.04 first http request is extremely slow

kg flag

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.

in flag
Pop!OS is not “basically Ubuntu” because System76 has gone and changed the boot mechanism, the DE, and a whole bunch of things under the hood, making the project a distinct operating system, and off-topic for this site. That said, you can ask this question [on Pop! Planet](https://pop-planet.info/), which is a forum dedicated to Pop!OS
CookieEater avatar
kg flag
@matigo I tried the same scenario on Ubuntu 20.04 and have the same scenario, so it does apply here. I can probably modify my question.
CookieEater avatar
kg flag
OK, it seems to work if I change the DNS server in `/etc/resolv.conf` to `8.8.8.8`. It's currently set to `127.0.0.53`. Why does Ubuntu provide this as a default, then?
Score:0
kg flag

As I wrote in the comment, It turns out to be a DNS server issue. I changed the DNS of my network to 8.8.8.8 (offered by Google). You can do this on Ubunte from Settings.

Picture of Network settings on Ubuntu

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.