pythonflaskjinja2flask-assets

Flask app slow if used by a small number of users in parallel


I have a Flask app with a few simple Jinja2 templates. In addition I use Flask-Assets/pyScss for CSS.

If a single users works with the app then everything works great. If a small number of people (less than 20) access the app in parallel then the response time sometimes goes way up and it feels like the server is not responding at all.

I tried: ab -n 1000 -c 20 http://myapp

But I wasn't able to reproduce the issue "artificially". How would you debug this kind of problem?


Solution

  • You are running the development server (app.run(), or perhaps ./manage.py runserver if using Flask-Script). It runs one thread by default, and shouldn't be used in production even with threading enabled. Instead, use a real application server such as uWSGI and proxy it behind a real web server such as Nginx. The Flask docs directly tell you not to use the dev server in production, and list multiple examples of how to get started deploying it properly.