HTTP service has a maximum number of concurrent requests. This caused a bug in one of my plugins, where the user ended up with a bad UX & they had to wait a while for a request to get through. If I had known about this limit in advance, I could have rearchitected my system to minimize concurrent connections.
Basically, my plugin needs to hear asynchronous updates from the server, and since I can’t open up my own TCP server in studio, I have to settle for doing HTTP long-polls to some HTTP server on the local PC. I had planned to have independent projects maintain their own polling loop, but this blows up on me when I exceed 2 projects.
The limit is set to 3 at the moment. I don’t need this limit raised. I just want the next person to not have a bug because of some undocumented behavior like I did.
(note: page currently talks about requests-per-minute limits, but not byte limits, or concurrent request limits)
How I arrived at my conclusion.
I set up a webserver in python whose role is to accept connections, yield a short while, and then return.
import http.server
import socketserver
import time
class YieldHandler(http.server.BaseHTTPRequestHandler):
def do_POST(self):
self.log_message("%s", "received post from {}:{}".format(*self.client_address))
time.sleep(3)
self.send_response(200, "OK")
self.end_headers()
self.log_message("%s", "responded to {}:{}".format(*self.client_address))
srv = http.server.ThreadingHTTPServer(("", 608), YieldHandler)
srv.daemon_threads = True
srv.serve_forever()
I then wrote a Lua script to execute a bunch of requests against this server in separate threads.
for i = 1, 12 do
spawn(function()
print(string.format("Thread %d attempting to connect...", i));
game:GetService("HttpService"):PostAsync("http://localhost:608/", "hi");
print(string.format("Thread %d received response", i));
end)
end
Reviewing the output of the execution shows:
C:\test-concurrent-httpservice-limits>python main.py
127.0.0.1 - - [20/Feb/2019 19:44:34] received post from 127.0.0.1:57176
127.0.0.1 - - [20/Feb/2019 19:44:34] received post from 127.0.0.1:57177
127.0.0.1 - - [20/Feb/2019 19:44:34] received post from 127.0.0.1:57178
127.0.0.1 - - [20/Feb/2019 19:44:37] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:37] responded to 127.0.0.1:57176
127.0.0.1 - - [20/Feb/2019 19:44:37] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:37] responded to 127.0.0.1:57177
127.0.0.1 - - [20/Feb/2019 19:44:37] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:37] responded to 127.0.0.1:57178
127.0.0.1 - - [20/Feb/2019 19:44:37] received post from 127.0.0.1:57182
127.0.0.1 - - [20/Feb/2019 19:44:37] received post from 127.0.0.1:57183
127.0.0.1 - - [20/Feb/2019 19:44:37] received post from 127.0.0.1:57184
127.0.0.1 - - [20/Feb/2019 19:44:40] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:40] responded to 127.0.0.1:57182
127.0.0.1 - - [20/Feb/2019 19:44:40] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:40] responded to 127.0.0.1:57183
127.0.0.1 - - [20/Feb/2019 19:44:40] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:40] responded to 127.0.0.1:57184
127.0.0.1 - - [20/Feb/2019 19:44:40] received post from 127.0.0.1:57188
127.0.0.1 - - [20/Feb/2019 19:44:40] received post from 127.0.0.1:57189
127.0.0.1 - - [20/Feb/2019 19:44:41] received post from 127.0.0.1:57190
127.0.0.1 - - [20/Feb/2019 19:44:43] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:43] responded to 127.0.0.1:57188
127.0.0.1 - - [20/Feb/2019 19:44:43] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:43] responded to 127.0.0.1:57189
127.0.0.1 - - [20/Feb/2019 19:44:44] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:44] responded to 127.0.0.1:57190
127.0.0.1 - - [20/Feb/2019 19:44:44] received post from 127.0.0.1:57195
127.0.0.1 - - [20/Feb/2019 19:44:44] received post from 127.0.0.1:57197
127.0.0.1 - - [20/Feb/2019 19:44:44] received post from 127.0.0.1:57198
127.0.0.1 - - [20/Feb/2019 19:44:47] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:47] responded to 127.0.0.1:57195
127.0.0.1 - - [20/Feb/2019 19:44:47] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:47] responded to 127.0.0.1:57197
127.0.0.1 - - [20/Feb/2019 19:44:47] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [20/Feb/2019 19:44:47] responded to 127.0.0.1:57198
I also ran wireshark for extra certainty. I don’t see the TCP SYNs start until after the number of concurrent connections drop below 3.