Concurrent Request Processing Issue in Flask with Gunicorn and Gevent-Websocket on AWS #5534
-
Hi everyone, I hope you're doing well. I'm currently working on a Flask project where I'm utilizing flask_login, flask_sqlalchemy, and flask_socketio. The application is deployed on AWS Elastic Beanstalk using Gunicorn .
I'm encountering an issue with request processing: when an I/O(database) operation is performed in one http request, other HTTP requests remain in the queue. According to the Flask-SocketIO documentation, increasing the -w (worker count) parameter beyond 1 is not suggested. Despite the application being load balanced , requests still get stuck in the queue. I understand that Flask operates as a WSGI server, but I am seeking a solution to enable concurrent request processing. I would greatly appreciate any suggestions or guidance on how to address this issue. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I don't understand how this is related to your problem. You are using gevent, so concurrency happens through greenlets, not worker processes. One Gunicorn worker can spawn up to 1000 greenlets, each handling one client. I think you need to look at how you run database queries. Whatever you are doing there must be blocking the gevent loop. |
Beta Was this translation helpful? Give feedback.
Gunicorn monkey patches by default when using the gevent worker, so I think SQLAlchemy should work fine.
My bet is that
mysqlconnector
, which is a C library, is incompatible with gevent. I would suggest you switch to pymysql for your database driver, that is more likely to work well with gevent's monkey patching because it is a pure Python library.