Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Update Gunicorn guide to use uvicorn-worker library #11855

Conversation

siavashyj
Copy link

@siavashyj siavashyj commented Jul 17, 2024

Update FastAPI Server Workers Documentation

Description

This PR updates the FastAPI Server Workers documentation to reflect the changes in Uvicorn worker implementation. The uvicorn.workers.UvicornWorker has been deprecated as of Uvicorn version 0.30.0, and we're now recommending the use of the uvicorn-worker package.

Changes

  • Updated installation instructions to include the uvicorn-worker package
  • Changed references from uvicorn.workers.UvicornWorker to uvicorn_worker.UvicornWorker
  • Updated the explanation of the --worker-class option to reflect the new import

Rationale

These changes are necessary to keep our documentation up-to-date with the latest best practices for deploying FastAPI applications with Gunicorn and Uvicorn workers.

Testing

  • Verified that the installation instructions work with the latest versions of the packages
  • Tested the Gunicorn command with the new worker class
  • Ensured that the document flow and overall structure remain intact

Additional Notes

Users upgrading from an older version may need to update their deployment scripts to use the new uvicorn_worker.UvicornWorker class. We may want to consider adding a migration guide or note in the documentation to help with this transition.

@tiangolo
Copy link
Member

📝 Docs preview for commit 98c1c8d at: https://af3405bf.fastapitiangolo.pages.dev

@alejsdev alejsdev changed the title docs: Update Gunicorn guide to use uvicorn-worker library. 📝 Update Gunicorn guide to use uvicorn-worker library. Jul 17, 2024
@alejsdev alejsdev added the docs Documentation about how to use FastAPI label Jul 17, 2024
@siavashyj siavashyj force-pushed the update-gunicorn-deployment-docs-to-use-uvicorn-worker branch from 98c1c8d to 5b057ce Compare July 19, 2024 14:08
@tiangolo
Copy link
Member

📝 Docs preview for commit 5b057ce at: https://9afd07f2.fastapitiangolo.pages.dev

@siavashyj
Copy link
Author

Ready to merge 🟢

@Kludex
Copy link
Member

Kludex commented Jul 21, 2024

My recommendation is to remove Gunicorn from the documentation.

@siavashyj
Copy link
Author

siavashyj commented Jul 21, 2024

My recommendation is to remove Gunicorn from the documentation.

I've had some not-so-great experiences running native Uvicorn workers on production instances due to: 1-potential memory leaks on long running instances, 2-slightly lower performance, 3-and higher tendency to timeout (502) under load compared to Gunicorn-Uvicorn workers.

I think keeping it as an option is still a good thing to have, especially for long running production instances.
What do you think @Kludex?

@KissPeter
Copy link

My recommendation is to remove Gunicorn from the documentation.

I've had some not-so-great experiences running native Uvicorn workers on production instances due to: 1-potential memory leaks on long running instances, 2-slightly lower performance, 3-and higher tendency to timeout (502) under load compared to Gunicorn-Uvicorn workers.

I think keeping it as an option is still a good thing to have, especially for long running production instances. What do you think @Kludex?

I can proof it with measurements:
https://kisspeter.github.io/fastapi-performance-optimization/workers_and_threads#gunicorn-vs-uvicorn

@Kludex
Copy link
Member

Kludex commented Jul 22, 2024

When did you do that?

Also... There's no need to prove anything here.

@alejsdev alejsdev changed the title 📝 Update Gunicorn guide to use uvicorn-worker library. 📝 Update Gunicorn guide to use uvicorn-worker library Aug 2, 2024
@siavashyj siavashyj force-pushed the update-gunicorn-deployment-docs-to-use-uvicorn-worker branch from 5b057ce to 8aa7fcc Compare August 10, 2024 16:02
Copy link
Contributor

@estebanx64
Copy link
Member

Hi @siavashyj

Thanks for your time and for helping us handle this topic. 🙇

We have planned to change these docs soon and we'll be reviewing it! 🤓

Copy link
Contributor

@tiangolo
Copy link
Member

Thanks for the interest @siavashyj!

I prefer to recommend the new Uvicorn with --workers, it's fewer moving parts, simpler code, and fewer chances of having errors and problems. 🤓

I updated the docs here: #12069, that should cover this.

I'll now close this one, but thanks for the effort! ☕

@tiangolo tiangolo closed this Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation about how to use FastAPI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants