I am considering the following setup:
- A "normal" flask app
- A socketio app
- Flask SocketIO
- gevent with Gunicorn, using
GeventWebSocketWorker
worker class - a single gunicorn worker
If you're really curious, here's the source tying it all together.
This seems to work, and be able to serve both normal HTTP traffic to the flask app as well as websockets to the socketio app. My question is: how? And how scalable is it (particularly regarding the websocket piece)?
My understanding of WSGI is that each request that comes in (http or websocket) will block a worker until the connection is terminated. This would mean that this setup would only be able to handle one websocket connection at a time. I've done enough experimenting to not think that's the case, but I still don't know how it works. Are the websockets being handled outside Gunicorn? If so, why do you have to give Gunicorn the GeventWebSocketWorker
class? If they are being handled from Gunicorn, how is that possible when Gunicorn is WSGI compliant and WSGI doesn't seem to really allow more than one connection per worker?
On top of these theoretical questions, I also want to know how many websocket connections I can handle with this setup (ballpark).