Is there any way to make the HttpService to keep a TCP or TCPS connection alive and reuse it? I’ve found that a HTTPS request that takes around 30ms in a browser takes about 500ms on a Roblox server and in studio. I’d like end up with around to 7-20ms latency using plain HTTP posts for my RBXMod service so that running latency sensitive scripts remotely is viable.
I can’t see any ways for you to do this, and I think I know why.
At the moment, there is a limit on the number of requests per minute which a game is allowed (correct me on that if it’s wrong). If a game could keep a connection alive, then you could circumvent the number of requests per minute allowed. So, everybody would overwhelm roblox infrastructure with requests being sent and open connections.
Of course, I might be totally wrong about this, but that’s my theory.
Ehh, I think being able to track requests per a minute would be implementation dependent. For example, if they simply obeyed the connection: keep-alive HTTP header like a browser, then they would still be able to count the number of times RequestAsync() was called.
I’m not sure why this isn’t a feature other than it requires a little more work. The fact is that implementing it would cut request latency in half. For small requests where most time is due to latency rather than file transfer (most requests), it would also cut total request time in half. Big benefit. This is because TCP wouldn’t have to send a connection request and hear back before it can send its actual request and get the response. No idea why they haven’t done it.
There’s no interface to directly handle anything other than the HTTP protocol. You’d have to try the Keep-Alive header. (Which you’ve already done it seems)
Actually, I had to perform a lot of setup to do proper testing. I think there were some lurking variables in my initial test, as it seems that Roblox servers cache connections by default and I am getting 16 ms latency right now. ^.^ The test connection lasted 10 minutes and beyond (I didn’t wait for it to close) and closes a couple seconds after I leave the game (and the Roblox server shuts down).
It wouldn’t circumvent the request limit, this is per HTTP (not TCP). If a single TCP connection can remain active then yes you could use that to send multiple HTTP requests, saving you some latency. The TCP connections are between two systems, you cannot reuse it with another host (because that’s not how TCP works or any transport layer communication for that matter). If you want to talk to a different host you’d need to establish a new connection.