is socket.http slow?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
dezoitodemaio
Prole
Posts: 15
Joined: Mon Oct 26, 2020 2:02 pm

is socket.http slow?

Post by dezoitodemaio »

I'm executing a simple GET with socket.http to my local api (json-server) and it's taking about 2 seconds to finish the request.

Is this normal?

Code: Select all

  local conn = require 'socket.http'

  print(os.time())
  local r, s = conn.request(url)
  print(os.time())
the above code produces:

Code: Select all

1610403955
1610403957
When i call the api from the browser the request returns almost instantly.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: is socket.http slow?

Post by pgimeno »

I get a pretty stable 334 ms when querying http://example.com. By the way, socket includes a gettime() function with sub-second precision:

Code: Select all

local url = 'http://example.com'
local gettime = require 'socket'.gettime
local conn = require 'socket.http'

local start = gettime()
local r, s = conn.request(url)
print(gettime() - start)
Not sure what the cause may be in your case. Perhaps your browser has cached the result and that's why it seems to respond much quickly.
dezoitodemaio
Prole
Posts: 15
Joined: Mon Oct 26, 2020 2:02 pm

Re: is socket.http slow?

Post by dezoitodemaio »

Well i should have tested it with another api before opening the thread, your example runs pretty fast in my machine too. I think the problem is json-server, for some reason it is slow when called from socket.http.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 39 guests