garrysmod-issues icon indicating copy to clipboard operation
garrysmod-issues copied to clipboard

HTTP Fetch/Post functions now take ~4x longer to send

Open marchc1 opened this issue 2 years ago • 4 comments

I realized last night that my http.Fetch/Post response times were elevated with a recent update. It seems like this problem comes from the recent fix to block local HTTP requests by doing a DNS query before every request.

But this has seemed to add significant amounts of latency to every single request. Before this update, I got similar latency increases, but only if I had not used that URL during that game session or if I hadn't used it in a while (guessing due to a DNS query). Now it happens every single request.

The latency increases are significant, too; previously I was able to get ~30ms response times from my server, but now I get nearly 110ms response times. One of my friends, who lives on the other side of the continent from my server, used to get ~100ms and now gets 400ms response times. I also tried the same test on a HTTP GET echo server, which had 80ms with browser and 300ms with gmod. One of my projects requires semi-quick response times (100ms pushes it but is acceptable), and this really messes with it.

This was all done client-side, but I did tests on the server and verified it happened there too.

To replicate, run this a few times in Garry's Mod:

local start = SysTime()
http.Fetch("https://httpbin.org/get", function()
    print((SysTime() - start) * 1000)
end)

and then run this a few times in a browser:

var start = new Date()
fetch("https://httpbin.org/get", {method: "GET"}).then((response) => {
    var end = new Date()
    console.log((end - start))
})

marchc1 avatar Sep 10 '23 08:09 marchc1

Should be better on dev.

robotboy655 avatar Sep 13 '23 20:09 robotboy655

Tested, latency is back to normal now, thank you!

marchc1 avatar Sep 13 '23 22:09 marchc1

@robotboy655 Can this issue be re-opened, since the patch had to be reverted?

marchc1 avatar Oct 10 '23 12:10 marchc1

Could potentially just cache the DNS response, that way repeated calls to the same host wouldn't be delayed. Using TTL as a cache time. I don't see anything bad that could happen in this scenario. Same rules as always (no local http), just faster.

xCynDev avatar Mar 23 '25 08:03 xCynDev