uvicorn-gunicorn-fastapi-docker | Docker image with Uvicorn | REST library
kandi X-RAY | uvicorn-gunicorn-fastapi-docker Summary
kandi X-RAY | uvicorn-gunicorn-fastapi-docker Summary
FastAPI has shown to be a Python web framework with one of the best performances, as measured by third-party benchmarks, thanks to being based on and powered by Starlette. The achievable performance is on par with (and in many cases superior to) Go and Node.js frameworks. This image has an auto-tuning mechanism included to start a number of worker processes based on the available CPU cores. That way you can just add your code and get high performance automatically, which is useful in simple deployments.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Print the version envs .
- Main entry point .
- Run a script .
- Read root message .
uvicorn-gunicorn-fastapi-docker Key Features
uvicorn-gunicorn-fastapi-docker Examples and Code Snippets
docker build -t mallapp .
docker run -d --name mycontainer -p 8030:8030 mallapp
docker run -d --name mycontainer -p 80:80 mallapp
Community Discussions
Trending Discussions on uvicorn-gunicorn-fastapi-docker
QUESTION
I'm looking to build a Docker image to run FastAPI on Google Cloud Run. FastAPI uses Uvicorn as an ASGI server and Uvicorn recommend using Gunicorn with the Uvicorn worker class for production deployments. FastAPI themselves also have some excellent documentation on using Gunicorn with Uvicorn. I even see that FastAPI provide an official image combining the two ( uvicorn-gunicorn-fastapi-docker) but this comes with a warning:
You are probably using Kubernetes or similar tools. In that case, you probably don't need this image (or any other similar base image). You are probably better off building a Docker image from scratch
This warning basically explains that replication would be handled at cluster-level and doesn't need to be handled at process-level. This makes sense. I am however not quite sure if Cloud Run falls into this category? Essentially it is an abstracted and managed Knative service which therefore runs on Kubernetes.
My question is, should I be installing Gunicorn along with Uvicorn in my Dockerfile and handling replication at process-level? Along the lines of:
...ANSWER
Answered 2021-Oct-13 at 18:54A. Let's go the big scale first.
At the time of writing Cloud Run instances can be set to a maximum of 1000 concurrency requests. And CPUs can be set to 4 vCPUs.
Going back to basics a bit. Cloud Run will span many instances, each will work individually, and each could handle the maximum allowed concurrency, so each could handle 1000 requests. If you set multiple CPUs you need to handle multi processes.
When we talk about so large number we need to be cautious. If your container is big enough in CPU/Memory terms to handle this traffic, you may want to use a process manager (gunicorn) to start several Uvicorn threads (workers), as your referenced images do. So you can use the docker container.
B. Being on small scale.
On the other hand if you set 1 vCPU and be single threaded, you don't need gunicorn for process manager. You still can have concurrency enabled but not on the top level, maybe at the lower level, that fits your 1 vCPU model, something like 80 requests for concurrency. In this situation you will have on large traffic, many instances started by Cloud Run, and you rely at Cloud Run to spawn as many instances as needed, which does really nice. It's like a Kubernetes on top of your simple container.
I would suggest start with single process, build a container that doesn't use the referenced container, and only swap B to version A, when you know there are benefits(costs wise) to have larger instances.
QUESTION
We are using the https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker FastAPI and were able to customize our logging with a gunicorn logging file.
However, we are not able to change the details of the %(message)s attribute as defined in the documentation access log - https://docs.gunicorn.org/en/stable/settings.html#accesslog.
We receive an error postet below, that the keys are unknown. A similar question has been asked before and received many upvotes. gunicorn log-config access_log_format
What are we doing wrong?
...ANSWER
Answered 2020-Nov-12 at 16:23Our solution was a customer logger written in python that is referenced in a logging.conf file
logging.conf
QUESTION
I want to use nginx as load balancer to my FastAPI replicas but i cannot get it to work. I read that uvicorn can also do it, but nginx would handle load balancing nicely. forum post.
I get an error
...ANSWER
Answered 2020-Apr-09 at 02:23As your nginx.conf file :
server inconnect:5001;
should be server inconnect1:5001;
And in docker compose file should use link
from nginx container to inconnect1
application. (remove network on nginx container)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install uvicorn-gunicorn-fastapi-docker
Go to your project directory.
Create a Dockerfile with:
Create an app directory and enter in it.
Create a main.py file with:
You should now have a directory structure like:
Go to the project directory (in where your Dockerfile is, containing your app directory).
Build your FastAPI image:
Run a container based on your image:
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page