I'm writing flask application that accepts POST requests with json data. I noticed huge differences in response time based on data size being passed to application. After debugging I narrowed down issue to the line where I was retrieving json data from request object. It may be important to note that testing was done on flask development server.

I timed this line and for data of 1024 (probably not coincidence) and less characters this took 0.002s and for anything over 1024 over 1 second!
What is happening here? Is this the limitation of development server?

EDIT:
Same thing happens for getting POST data through request.form.get('somedata') with content lenght over 1024

EDIT:
I couldn't replicate issue with same example served by Apache

EDIT:
I started digging into Werkzeug module and found that slowness occurs when reading response message self._read(to_read) in wsgi.py module which is passed from BaseHTTPRequestHandler. Still don't know why so slow.

I have had problems using BaseHTTPRequestHandler in bottle, not flask. But it may be the same problem, the development environment is trying to resolve the ip address into host names, so they delay could be that lookup timing out. blog.est.im/post/34288214582 Maybe this is a strecht, but it might lead you in right direction.
–
i_4_gotNov 30 '12 at 18:20

2 Answers
2

You can use the builtin server during development, but you should use a full deployment option for production applications. (Do not use the builtin development server in production.)

As Marcus mentioned in the comments, another WSGI server like gunicorn or tornado would be much faster and more reliable, so definitely use one of those for deployment and benchmarking.

If you're worried about working quickly during development, you can use gunicorn in development just like you would in deployment. If you're deploying to heroku, for example, you can run "foreman start" and the gunicorn server will start right up.