r/FastAPI • • Aug 15 '22

Question raw Flask vs FastAPI ?

According to tech empower benchmark, if I use Flask without ORM library, it performs faster than FastAPI. Raw Flask could handle 13,574 requests per second. FastAPI could handle 12,406 req /s. Flask with an ORM library could handle only 552 req /s.

Do you guys think this is true? is Flask still faster than FastAPI? then develoeprs can stick with Flask with raw SQL queries.

Here's a link to flask-raw github repo:

https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/Python/flask/app_raw.py

4 Upvotes

12 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Aug 15 '22

4

u/sv_ds Aug 15 '22

Im sorry but you asked the question like this was the end of the world or at least FastApi. But no sane dev chooses a framework based on the raw requests per seconds.

3

u/[deleted] Aug 15 '22

I mean, I had an impression that Flask is significantly slower than FastAPI... that's true only when you use Flask with an ORM library. But if you use raw Flask, its performance won't be too behind FastAPI. I found that to be surprising.

2

u/MoRakOnDi Aug 15 '22

Flask is NOT significantly slower than FastAPI. But Flask uses threading for concurrency and it's I/O is blocking. FastAPI on the other hand uses asyncio which relies on cooperative concurrency and nonblocking I/O. All that means is Flask needs more RAM for certain amount of RPM than FastAPI, if all implemented correctly. Usually people make many mistakes in implementing Asyncio, so FastAPI could be tricky. On the other hand, if you don't need huge DB transactions for your app, Flask wouldn't suffer from blocking I/O. It all depends on use-case, team's familiarity with cooperative async, and the project requirements.