#Flask server failing when load increases

14 messages · Page 1 of 1 (latest)

amber oak
#

I've deployed a flask server and it works totally fine if I test it on a dev Vercel deployment, but as soon as I switch the prod backend to the railway flask server and start getting high traffic, I get this weird error over and over. Definitely a traffic thing because it even works for the first few seconds that I deploy, but quickyl get CORS error, presumably because the server can't send back headers.

2024-02-25 18:05:24 +0000] [11] [ERROR] Socket error processing request.
Traceback (most recent call last):
File "/opt/venv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 133, in handle
req = next(parser)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/parser.py", line 41, in __next__
self.mesg = self.mesg_class(self.cfg, self.unreader, self.req_count)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 186, in __init__
super().__init__(cfg, unreader)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 53, in __init__
unused = self.parse(self.unreader)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 235, in parse
self.headers = self.parse_headers(data[:idx])
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 73, in parse_headers
remote_addr = self.unreader.sock.getpeername()
OSError: [Errno 107] Transport endpoint is not connected
stiff tideBOT
#

Project ID: ce32fe10-d6e2-48b8-97c2-1f14b564dc39

amber oak
#

ce32fe10-d6e2-48b8-97c2-1f14b564dc39

late schooner
#

have you tried increasing the workers and threads?

amber oak
#

how do I do that?

late schooner
#

have a read of gunicorns docs, they provide flags to set the number of workers and threads gunicorn will use

amber oak
#

upping the number of replicas seems to have done the trick!

late schooner
#

i would try with a single replica but with more workers and threads

amber oak
#

railway runs the flask server for me though, would you suggest switching to a docker container so I can actually set these parameters?

late schooner
#

railway does not run the server for you, you are in full control of whats ran at all times

#

most python users have their start commands defined in a Procfile

amber oak
#

ohh got it thanks

amber oak
#

performance is great! thanks for saving our app!

late schooner
#

no problem!