Skip to content

High CPU usage while using on production using nginx #4373

@ashutoshsingh25

Description

@ashutoshsingh25

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

Description=Gunicorn instance to serve myproject
After=network.target

[Service]
User=user
Group=www-data
WorkingDirectory=/home/My_Api
Environment="PATH=/home/My_Api/myproject/myprojectenv/bin"
ExecStart=/home/My_Api/myproject/myprojectenv/bin/gunicorn -w 17 -k uvicorn.workers.UvicornWorker asgi:app --bind unix:app.sock


[Install]
WantedBy=multi-user.target

Description

I have planned my migrate one of my API from flask to fastapi.
While using it in production on a 8 vCPUs server, it start running fine for first 10 mins and after that one or two CPU usage reach to 100%.
I am using gunicorn, uvicorn and nginx to server the same on production.

I have developed the same application in the flask with Nginx and gunicorn and its running perfectly fine on same server for same number of requests.

Sharing screenshot for CPU usage
image

Operating System

Linux

Operating System Details

Ubuntu 20.1

FastAPI Version

0.70.1

Python Version

3.8.1

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions