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
American Airlines Business Class vs. First Class - NerdWallet
Qualys Malware Detection Service
Kem Minnick Playboy
Riverrun Rv Park Middletown Photos
Canya 7 Drawer Dresser
Metallica - Blackened Lyrics Meaning
How To Be A Reseller: Heather Hooks Is Hooked On Pickin’ - Seeking Connection: Life Is Like A Crossword Puzzle
Sissy Hypno Gif
Sam's Club Gas Price Hilliard
What is international trade and explain its types?
Orlando Arrest and Public Records | Florida.StateRecords.org
South Bend Tribune Online
Amelia Bissoon Wedding
C Spire Express Pay
Mary Kay Lipstick Conversion Chart PDF Form - FormsPal
Craigslist Farm And Garden Cincinnati Ohio
ᐅ Bosch Aero Twin A 863 S Scheibenwischer
iLuv Aud Click: Tragbarer Wi-Fi-Lautsprecher für Amazons Alexa - Portable Echo Alternative
Northern Whooping Crane Festival highlights conservation and collaboration in Fort Smith, N.W.T. | CBC News
Straight Talk Phones With 7 Inch Screen
Nesz_R Tanjiro
De beste uitvaartdiensten die goede rituele diensten aanbieden voor de laatste rituelen
Robeson County Mugshots 2022
Doublelist Paducah Ky
Egizi Funeral Home Turnersville Nj
Fleet Farm Brainerd Mn Hours
Silky Jet Water Flosser
Hctc Speed Test
Pioneer Library Overdrive
Wonder Film Wiki
Cal State Fullerton Titan Online
Farm Equipment Innovations
10-Day Weather Forecast for Santa Cruz, CA - The Weather Channel | weather.com
Worthington Industries Red Jacket
Skepticalpickle Leak
Martin Village Stm 16 & Imax
Baldur's Gate 3 Dislocated Shoulder
Song That Goes Yeah Yeah Yeah Yeah Sounds Like Mgmt
About Us | SEIL
CVS Near Me | Somersworth, NH
Scottsboro Daily Sentinel Obituaries
Pp503063
The Closest Walmart From My Location
2020 Can-Am DS 90 X Vs 2020 Honda TRX90X: By the Numbers
Thelemagick Library - The New Comment to Liber AL vel Legis
Invalleerkracht [Gratis] voorbeelden van sollicitatiebrieven & expert tips
If You're Getting Your Nails Done, You Absolutely Need to Tip—Here's How Much
BCLJ July 19 2019 HTML Shawn Day Andrea Day Butler Pa Divorce
Caphras Calculator
Premiumbukkake Tour
A Man Called Otto Showtimes Near Cinemark Greeley Mall
Tyrone Dave Chappelle Show Gif
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.