How to make flask able to handle large number of io requests?

7 hours ago 8

Hey guys, what might be the best way to make flask handle large number of requests which simple wait and do nothing useful. Example say fetching data from an external api or proxying. Rn I am using gunicorn. With 10 workers and 5 threads. So that's about 50 requests at a time. But say I got 50 reqs and they are all waiting on something, the new reqs would wait in queue.

What's the solution here to make it more like nodejs (or fastapi) which from what I hear can handle 1000s of such requests in a single worker. I have an existing codebase and I am unsure I wanna migrate it to fastapi. I also have a nextjs frontend. And I could delegate such tasks to nextjs but seems like splitting logic between 2 backends is kinda bad. Plus I like python and would wanna keep most of the stuff in python.

I have plenty of ram and could just increase to more threads say 50 per worker. From what I read the options available are gevent and WsgiToAsgi but unsure how plug and play they are. And if they have any mess associated with them since they are plugins forcing flask to act like async.

For now I think adding more threads will suffice. But historically had some issues. Let me know if you have any experience or any solution on what might be best way possible.

submitted by /u/Consistent_Tutor_597 to r/Python
[link] [comments]
Read Entire Article