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.
-
dezoitodemaio
- Prole
- Posts: 15
- Joined: Mon Oct 26, 2020 2:02 pm
Post
by dezoitodemaio » Mon Jan 11, 2021 10:38 pm
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:
When i call the api from the browser the request returns almost instantly.
-
pgimeno
- Party member
- Posts: 2484
- Joined: Sun Oct 18, 2015 2:58 pm
Post
by pgimeno » Tue Jan 12, 2021 11:23 am
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
Post
by dezoitodemaio » Tue Jan 12, 2021 11:48 am
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.
Users browsing this forum: GVovkiv and 59 guests