question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Slower behavior using Fast API (same gunicorn config) Gunicorn with uvicorn.workers.UvicornWorker than using default one

See original GitHub issue

I’m using this dependencies:

starlette==0.13.6 uvicorn==0.11.8 fastapi==0.61.1

According to every check I’ve worked with, using FastAPI is supposed to handle more request per second than a Flask App but I’m finding different behaviors.

  • Using Flask + Gunicorn, I’m getting twice the number of req/s vs using FastAPI + Gunicorn(uvicorn.workers.UvicornWorker)

The other params (besides the worker class) are the same for both apps.

What can I check to improve this ? or is this the expected behavior? If so, what could be other places I could look into to improve the performance of using FastAPI ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ycdcommented, Oct 10, 2020

It’s kinda hard to tell without code and how you benchmarking them (running options etc.)

Also, I did some benchmarking you might want to check it out

1reaction
ycdcommented, Oct 10, 2020

Yes, please add these,

How do you run FastAPI, and options?

  • Example: uvicorn your:app --workers int

How do you run Flask, and running options?

  • Example: waitress-serve --call "your:app"

The code that you use for testing FastAPI


from fastapi import FastAPI, Request

app = FastAPI()

@app.get("/etc")
async def etc(request: Request):
    return await request.body()

The code that you use for testing Flask

from flask import Flask

...

etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Workers - Gunicorn with Uvicorn - FastAPI
Here I'll show you how to use Gunicorn with Uvicorn worker processes. ... Then Gunicorn would start one or more worker processes using...
Read more >
Deployment - Uvicorn
Gunicorn is probably the simplest way to run and manage Uvicorn in a production setting. Uvicorn includes a gunicorn worker class that means...
Read more >
Fastapi python code execution speed impacted by ...
@NaveenReddyMarthala Yes, I think in your case you can use just Uvicorn. But using gunicorn with single uvicorn worker may still give you...
Read more >
FastAPI vs. Express.js vs. Flask vs. Nest.js Benchmark
I wanted to verify FastAPI's claims of having performance on par with Node.js. ... Flask + psycopg2 + gunicorn (1 worker). $ gunicorn...
Read more >
Gunicorn Worker Types: How to choose the right one
This article assumes you're using a sync framework like flask or Django and won't explore the possibility of using the async/await pattern.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found