title: Flask app run with Gunicorn async workers appears less efficient than dev server
body: <p>I've got a web app developed in Flask. The setup is simple. The app is running on Gunicorn. All requests are proxied through the nginx. The Flask app itself makes HTTP requests to external API. The HTTP requests from the flask app to the external API are initiated by AJAX calls from the javascript code in the frontend. The external API returns data in JSON format to the Flask app and the back to the frontend. </p>
  
  <p>The problem is that when I run this app in development mode with the option <code>multithreaded = True</code> I can see that the JSON data get returned asynchronously to the server and I can see the result on the frontend page very quickly. </p>
  
  <p>However, when I try to run the app in production mode with nginx and gunicorn I see that the JSON data get returned sequentially - quit slowly, one by one. It seems that due to some reason the HTTP requests to the external API get blocked.</p>
  
  <p>I use supervisor on linux Ubuntu Server 16.04. This is how I start gunicorn through supervisor:</p>
  
  <pre><code>command = /path/to/project/env/bin/gunicorn -k gevent --worker-connections 1000 wsgi:app -b localhost:8500
  </code></pre>
  
  <p>It seems that gunicorn does not handle the requests asynchronously, although it should.</p>
  
  <p>As experiment I ran the Flask app using it's built in wsgi server (NOT gunicorn) in development mode, with <code>debug=True</code> and <code>multithreaded=True</code>. All  requests were still proxied through the nginx. The JSON data returned much quicker, i.e. asynchronously (seems the calls did not block).</p>
  
  <p>I read gunicorn's documentation. It says if I need to make calls to external API, then I should use async workers. I use them but it doesn't work.</p>
  
  <p>All the caching stuff was taken into account. I may assume that I don't use any cache. I cleared it all when I checked the server setups.</p>
  
  <p>What am I missing? How can I make gunicorn run as expected?</p>
  
  <p>Thanks.</p>