Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle 1000 concurrent requests for Flask/Gunicorn web service

I am fairly new to creating web services in Python. I have created a Flask web service successfully and run it with Gunicorn (as Flask’s built-in server is not suitable for production). This is how I run my app (with 4 worker nodes).

   gunicorn --bind 0.0.0.0:5000 My_Web_Service:app -w 4

The problem is, this only handles 4 requests at a time. I want it to be able to handle potentially 1000's of requests concurrently. Should I be using multi-threading? Any other options/suggestions?

like image 722
Swapnil Avatar asked Jul 12 '17 21:07

Swapnil


1 Answers

Reading the section on Workers you have to switch to an async worker, which can handle thousands of connections, if your work is IO bound. Using more processes than CPUs is not recommended.

like image 139
Daniel Avatar answered Oct 12 '22 23:10

Daniel