Flask on Heroku: request.form is incredibly slow with big POST data?

I am running the Flask application on Heroku using gunicorn with eventlet workers. A specific route in my application often receives POST data (x-www-form-urlencoded) with fairly short fields - no more than 500 KB.

This works fine when working locally, but on Heroku, requests for this route take from 5 to 30 seconds, and almost 100% of the time is spent on the first access to request.form:

t = time.time()
action = str(request.form['action'])
dt = time.time() - t  # Often 10 seconds or more!

This is also confirmed by Newrelic slow query tracking. There a few milliseconds here or there for database operations, and then a huge chunk of time in Python code, apparently spent waiting for some I / O operations, since the indicated processor time is usually less than a millisecond.

I was completely unable to reproduce this in the local environment using the same gunicorn / eventlet setting that I use in the production process. Even the built-in WSGI debug server responds quickly to these requests.

Does anyone know what could be wrong? Is this a problem with Flask, or is there something I just need to associate with Heroku support?

+5
source share
1 answer

I think I understood what was happening. TL DR it wasn’t slow at all on the server, I was just misled by the Newrelic response time messages!

dotCloud, @AllanAnderson. : HTML , 900 , , , request.form , time.time().

Heroku :

5.87100 seconds: read field "p1": 786432 bytes
0.00019 seconds: read field "p2": 131072 bytes
0.00003 seconds: read field "p3": 12288 bytes
0.00001 seconds: read field "p4": 1024 bytes

dotCloud:

0.00096 seconds: read field "p1": 786432 bytes
0.00019 seconds: read field "p2": 131072 bytes
0.00003 seconds: read field "p3": 12288 bytes
0.00001 seconds: read field "p4": 1024 bytes

, , ... , , , "".: -)

, gunicorn Heroku , , request.form , . , Newrelic , POST . dotCloud, -, , .

Newrelic , .

+3

All Articles