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

22

u/[deleted] Aug 15 '22

perhaps there is some other reason why people choose web frameworks besides for executing raw sql

8

u/[deleted] Aug 15 '22

Go with what you/team knows and are happy with. The speed difference is so negligible that it will have no implication (12406 vs 13574). The real question is how many requests your application will get per second?

5

u/zarlo5899 Aug 15 '22 edited Aug 15 '22

he speed difference is so negligible that it will have no implication

yep you can always just spin up more instance of the program any ways

7

u/ShotgunPayDay Aug 15 '22

You can use the raw asyncpg adapter with FastAPI. I prefer to use aioSQL with asyncpg to make folder structure management easy.

5

u/pint Aug 15 '22

try to sell this to a manager. we are going to handle less than 10% more requests, and increase development time significantly meanwhile.

1

u/sv_ds Aug 15 '22

You haven't shown the FastApi code, but even if its true: so what?

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.

1

u/TokyotoyK Aug 16 '22

ORM is really nice though and something a lot of developers want for a reason :-)

1

u/extreme4all Oct 02 '22

We used to have issues with flask that the queue would fill up if we had a few heavy db requests, we don't have this with fast api. Also you might want to read thz fast api doc on performance