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.

Fastapi recommends use gunicorn with uvicorn workers why?

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}

Description

Currently i use uvicorn only in production but when i check the docs it says you should run uvicorn workers inside gunicorn, what do i get when i replace it with gunicorn?

Operating System

Linux

Operating System Details

No response

FastAPI Version

latest

Python Version

3.9

Additional Context

No response

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
adriangbcommented, Oct 14, 2021

I think it’s important to look at the bigger picture in a production setup. If you’re running containerized, replicated deployments on k8s, you don’t really need a process manager for resiliency or upgrades. What you do need however is good load balancing, and Gunicorn / Uvicorn workers (well, really the OS itself) provide that. k8s load balancing is just iptables by default I believe, so not even round robin.

3reactions
insomnescommented, Oct 14, 2021

You can read exactly what you search in uvicorn documentation: https://www.uvicorn.org/deployment/#using-a-process-manager

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Workers - Gunicorn with Uvicorn - FastAPI
You can use Gunicorn (or also Uvicorn) as a process manager with Uvicorn workers to take advantage of multi-core CPUs, to run multiple...
Read more >
FastAPI Gunicorn Uvicorn for Production Deployment with ...
It is not a bad idea to use tiangolo/uvicorn-gunicorn but I recommend you to lock the version of the container, this is in...
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 >
tiangolo/uvicorn-gunicorn - Docker Image
You can use Gunicorn to start and manage multiple Uvicorn worker processes. That way, you get the best of concurrency and parallelism in...
Read more >
The Ultimate FastAPI Tutorial Part 6b - Basic Deployment on ...
Then Gunicorn would start one or more worker processes using that class. And Uvicorn has a Gunicorn-compatible worker class. Using that ...
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