Is FastAPI fast enough? (2024)

All the code in this article is available on my Github repo.

For comparing benchmarking results of FastAPI, I’ve used the gin HTTP framework from go and express from NodeJS.

In my journey of enterprise software development, I came across numerous articles claiming Python to be a shining star in terms of web app development. In those, one of the most talked-about frameworks is FastAPI for python and Express for JS. It is evident when compared to other popular frameworks.

Is FastAPI fast enough? (2)

After using FastAPI for developing APIs and scaling it for IoT applications, I experienced its struggles handling more than 10000 requests/sec without increasing virtual machine instances. So I decided to benchmark this highly decorated framework against other options (Gin and Express). The results of this test came as a surprise to me because of the claim made on FastAPIs documentation.

Is FastAPI fast enough? (3)

Results of the Test

Is FastAPI fast enough? (4)

There are some important metrics that I want to point out here.

  1. Average time per request: Time difference between request reaching API server and leaving the server. (Lower the better)
  2. Requests per second: Number of requests served per second. (Higher the better)

From simple math, we can see that Express and Gin are 2.6 and 14.8 times faster than FastAPI respectively in terms of average time per request. Also, Express and Gin can serve 4.7 and 12 times more requests than FastAPI respectively in the same time period. How can these results be on par with NodeJS and Go?

These results pushed me to rethink my goto framework of choice which previously WAS FastAPI.

What does this benchmarking test do?

In order to rule out language preference load testing, I’m not using Python’s Locust, Go’s Vegeta, and Javascripts’ Loadtest. Instead, I opted for Rust’s Drill.

Since we’re testing different types of languages (Compiled / Interpreted), I will not perform any compute-intensive or I/O bound task. The goal here is to test how many requests can these frameworks handle and what are the response timings.

I have created 1 endpoint in each framework that returns a 200 OK response with the following JSON.

{
"status": 200,
"message": "Success"
}

Want to run these benchmarks yourself?

You need to clone this repository: https://github.com/ypatel-93/benchmark-fastapi_gin_express

Since I’m a Unix spoiled brat, and never touched a Windows system, this tutorial will run smoothly if you have a Linux or Mac OS. Also, you have to make sure you have python3.6+, go 1.13+, Nodejs16+, npm 7+, and Rust and Cargo 1.59+ installed.

There is a shell script in the repo named test_setup.sh, it will make necessary setups for you. You need to make it executable before running it.

sudo chmod +x test_setup.sh

Note: You will need to press ENTER for all questing asked during NodeJS setup.

In case installation fails using the setup script or you want to do it yourself, please follow the steps from the official installation guides for FastAPI, Gin, and Express.

Running Apps and Testing

There is a drill_test.sh script in the repo. Make it executable

sudo chmod +x drill_test.sh

I have configured it so that FastAPI, gin, and the express apps will run on ports 8001, 8002, and 8003 respectively.

Your terminal should print test logs as the apps are tested.

Happy Testing 😬

Thanks for reading!

Is FastAPI fast enough? (2024)
Top Articles
Minimum System Requirements Definition | Law Insider
Create a username - Gmail Help
Cappacuolo Pronunciation
Genesis Parsippany
Craigslist Niles Ohio
Big Spring Skip The Games
Sam's Club Gas Price Hilliard
30% OFF Jellycat Promo Code - September 2024 (*NEW*)
CHESAPEAKE WV :: Topix, Craigslist Replacement
123 Movies Babylon
Catsweb Tx State
Walgreens On Nacogdoches And O'connor
Canvas Nthurston
Urban Airship Expands its Mobile Platform to Transform Customer Communications
Hanger Clinic/Billpay
Loft Stores Near Me
Hdmovie 2
Marine Forecast Sandy Hook To Manasquan Inlet
Gran Turismo Showtimes Near Marcus Renaissance Cinema
Holiday Gift Bearer In Egypt
What Is a Yurt Tent?
Garden Grove Classlink
NV Energy issues outage watch for South Carson City, Genoa and Glenbrook
Bfsfcu Truecar
Rs3 Bring Leela To The Tomb
Current Time In Maryland
How does paysafecard work? The only guide you need
Steven Batash Md Pc Photos
El agente nocturno, actores y personajes: quién es quién en la serie de Netflix The Night Agent | MAG | EL COMERCIO PERÚ
Black Adam Showtimes Near Amc Deptford 8
#1 | Rottweiler Puppies For Sale In New York | Uptown
Soulstone Survivors Igg
Finland’s Satanic Warmaster’s Werwolf Discusses His Projects
Walgreens Agrees to Pay $106.8M to Resolve Allegations It Billed the Government for Prescriptions Never Dispensed
Myanswers Com Abc Resources
Timberwolves Point Guard History
Bcy Testing Solution Columbia Sc
Parent Portal Pat Med
Az Unblocked Games: Complete with ease | airSlate SignNow
Online-Reservierungen - Booqable Vermietungssoftware
Reilly Auto Parts Store Hours
Value Village Silver Spring Photos
Worland Wy Directions
The Machine 2023 Showtimes Near Roxy Lebanon
Actress Zazie Crossword Clue
Terrell Buckley Net Worth
Euro area international trade in goods surplus €21.2 bn
Twizzlers Strawberry - 6 x 70 gram | bol
Rise Meadville Reviews
Tamilyogi Cc
Unity Webgl Extreme Race
Wayward Carbuncle Location
Latest Posts
Article information

Author: Nicola Considine CPA

Last Updated:

Views: 6301

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Nicola Considine CPA

Birthday: 1993-02-26

Address: 3809 Clinton Inlet, East Aleisha, UT 46318-2392

Phone: +2681424145499

Job: Government Technician

Hobby: Calligraphy, Lego building, Worldbuilding, Shooting, Bird watching, Shopping, Cooking

Introduction: My name is Nicola Considine CPA, I am a determined, witty, powerful, brainy, open, smiling, proud person who loves writing and wants to share my knowledge and understanding with you.