惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy International News Feed
I
Intezer
T
Tenable Blog
S
Schneier on Security
Project Zero
Project Zero
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
Know Your Adversary
Know Your Adversary
博客园 - 司徒正美
The Cloudflare Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
News and Events Feed by Topic
博客园 - 叶小钗
宝玉的分享
宝玉的分享
L
LINUX DO - 热门话题
aimingoo的专栏
aimingoo的专栏
S
Secure Thoughts
Forbes - Security
Forbes - Security
T
The Exploit Database - CXSecurity.com
D
Darknet – Hacking Tools, Hacker News & Cyber Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
罗磊的独立博客
IT之家
IT之家
H
Hacker News: Front Page
I
InfoQ
云风的 BLOG
云风的 BLOG
S
Security Affairs
M
MIT News - Artificial intelligence
GbyAI
GbyAI
Jina AI
Jina AI
Help Net Security
Help Net Security
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
Webroot Blog
Webroot Blog
L
Lohrmann on Cybersecurity
A
About on SuperTechFans
Attack and Defense Labs
Attack and Defense Labs
The Register - Security
The Register - Security
V
V2EX
G
Google Developers Blog
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
J
Java Code Geeks
W
WeLiveSecurity
Cloudbric
Cloudbric
T
Tor Project blog

ashishb.net

A day in Luxembourg - the richest country in the world I was asked to install malware during a fake interview Book summary: Breakneck - China's quest to engineer the future by Dan Wang Book summary: How to Teach Your Baby to Read Book Summary: The Discontented Little Baby Book by Pamela Douglas Introducing Amazing Sandbox - run third-party tools and AI agents securely on your machine Why software outsourcing gets a bad reputation? Book summary: The Natural Baby Sleep Solution by Polly Moore A day in Antwerp, Belgium Journey of online influencers Two days in Brussels, Belgium Shortcuts - when we love them and when we don't A visit to Rakhigarhi Three days in overhyped Paris Empty Japan, crowded Tokyo The real lock-in in GitHub is not the code, but the stars 11-day Norwegian Breakaway East Caribbean cruise Sanskrit and Sri Lankan Air Force Use REST with Open API The Achilles heel of American capitalism Costa Rica in 4 days At a juice stall in Sri Lanka A short stay at Warsaw, Poland Best practices for using Python & uv inside Docker Two days in Vilnius, Lithuania How IntelliJ IDEs waste disk space Pregnancy Why there aren't many digital nomads from India Two days in Riga, Latvia To keep your machine secure, run third-party tools inside Docker Family Ties in Your DNA: Some relatives are closer than others Doctors per capita Two days in Tallinn, Estonia Ship tools as standalone static binaries Made in America Two days in Helsinki, Finland Maintaining an Android app is a lot of work The land of good deals Two days in Oslo, Norway Google Search is losing to Perplexity Two days in Dublin, Ireland Continuous integration ≠ Continuous delivery World's simplest project success heuristic London in 5 days It is hard to recommend Python in production Inflation, IRS, Credit cards, and Vendors Temu and the Chinese approach Things to do in Miami Florida Revenue vs Cost Axis Language learning as an adult The unanchored babies of the green card limbo Price variance in the United States A day in Louisville, Kentucky A surprisingly positive experience with Air India Unhospitable Airports Android: Don't use stale views USA = Union of Sales and Advertisement A day in Nashville, Tennessee Minimize Javascript in your codebase A day in Birmingham, Alabama In defense of ad-supported products Real vs artificial world The science behind Punjabi singers Hiking Mt. Fuji The Indian startup bubble is insane Repairing database on the fly for millions of users Book Summary: One up on Wall Street by Peter Lynch It is hard to recommend Google Cloud At the Prague airport Kyoto in three days Migrating from WordPress to Hugo Book summary: Sick Societies by Robert B. Edgerton Statistical outcomes require statistical games Illegal immigrants to Europe via Cairo Tokyo in three days Mobs are Status Games Writing Script matters as much as the spoken language Sri Lanka in 5 days LLMs: great for business but bad business Book Summary: Safe Haven by Mark Spitznagel Mac shortcut for typing Avagraha symbol On a bus with an asylum seeker Nicaragua in 5 days When to commit Generated code to version control Why I always buy a local SIM in a foreign country Use Makefile for Android Four days in Guadalajara, Mexico Android Navigation: Up vs Back Hotels vs Airbnb vs Hostels Currency issues in Argentina Abstractions should be deep not wide Some data on podcasting Always support compressed response in an API service A day in El Calafate - Patagonia, Argentina Hermetic docker images with Hugging Face machine learning models American Elections The sound of "ch" API services should always have usage Limits Hiking in El Chaltén - trekking capital of Argentina Natural Laws vs Man-made Laws
FastAPI vs Flask performance comparison
Ashish Bhatia · 2025-05-10 · via ashishb.net

If you are running Python in production, you will almost certainly have to decide which web framework to use.

Let’s consider a rudimentary Hello world based test comparing the performance of two popular web frameworks for Python - FastAPI and Flask.

I will intentionally use Docker for benchmarking as most deployments today will explicitly or implicitly rely on Docker.

For Flask, I will use this

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Build: docker buildx build -t python-flask -f Dockerfile_python .
# Size: docker image inspect python-flask --format='{{.Size}}' | numfmt --to=iec-i
# Run: docker run -it --rm --cpus=1 --memory=100m -p 8001:8001 python-flask
FROM python:3.13-slim AS base

WORKDIR /app
RUN pip3 install --no-cache-dir flask gunicorn
SHELL ["/bin/bash", "-c"]
RUN echo -e "\
from flask import Flask\n\
app = Flask(__name__)\n\
\
@app.get('/')\n\
def root():\n\
  return 'Hello, World!'\n\
" > /app/web_server.py

ENTRYPOINT ["gunicorn", "web_server:app", "--bind=0.0.0.0:8001", "--workers=4", "--threads=32"]

And for FastAPI, I will use this

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Build: docker buildx build -t python-fastapi -f Dockerfile_python .
# Size: docker image inspect python-fastapi --format='{{.Size}}' | numfmt --to=iec-i
# Run: docker run -it --rm --cpus=1 --memory=100m -p 8002:8002 python-fastapi
FROM python:3.13-slim AS base

WORKDIR /app
RUN pip3 install --no-cache-dir fastapi gunicorn uvicorn
SHELL ["/bin/bash", "-c"]
RUN echo -e "\
from fastapi import FastAPI\n\
app = FastAPI()\n\
@app.get('/')\n\
async def root():\n\
    return {'message': 'Hello World'}\
" > /app/web_server.py

ENTRYPOINT ["gunicorn", "web_server:app", "--bind=0.0.0.0:8002", \
  "-k uvicorn.workers.UvicornWorker", "--workers=4", "--threads=32"]

As you will notice the only difference is the framework used. The rest of the code is exactly the same.

Comparing the result, we can see FastAPI is 3X faster in these basic requests.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$ h2load --h1 -n1000 -c40 'http://localhost:8001'  # Flask
...
                      min         max         mean         sd        +/- sd
time for request:      406us     83.37ms     12.56ms     22.46ms    86.70%
...
req/s           :      75.98       83.04       79.36        2.08    60.00%

$ h2load --h1 -n1000 -c40 'http://localhost:8002'  # FastAPI results
...
                      min         max         mean         sd        +/- sd
 time for request:      825us     29.78ms      4.07ms      6.13ms    91.70%
# req/s           :     231.07      256.41      241.98        8.86    52.50%
...

So, in terms of throughput, I am fairly convinced that no one should choose Flask over FastAPI for new projects.

Even if query serving time is only 20% of the end to end latency, one gets about 15% performance improvement by choosing FastAPI over Flask.

Even if you decide to use Flask, given its single threaded nature, use it behind gunicorn, the way I used above

It is definitely concerning though that FastAPI, as of 2025, is not stable release yet.