簡體   English   中英

我的 fastapi 應用程序在生產服務器上被壓垮了,但也在本地主機上工作

[英]My fastapi app getting crushed on production server but also working on localhost

每隔一兩個小時,我的 fastapi 應用程序就會崩潰。 我可以從我的服務器上看到這些日志。

[UID:1438][3585218] Child process with pid: 3585712 was killed by signal: 15, core dump: 0
[UID:1438][3647755] Child process with pid: 3647765 was killed by signal: 15, core dump: 0
[UID:1438][3647755] Child process with pid: 3647775 was killed by signal: 15, core dump: 0

我有其他 python 應用程序在我的服務器上運行,沒有任何問題。 每隔一兩個小時,我的 fastapi 應用程序就會崩潰。 這是我的database.py代碼

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
 

SQLALCHEMY_DATABASE_URL = "mysql+pymysql://<>:@<>/<>"

engine = create_engine(
    SQLALCHEMY_DATABASE_URL
)

SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()


def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

主程序

class Settings(BaseSettings):
    openapi_url: str = "/openapi.json"


settings = Settings()

app = FastAPI(openapi_url=settings.openapi_url)

origins = [
     
    "http://localhost:3000",
     
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
     
     
    
)


#create tables
models.Base.metadata.create_all(engine) 
app.include_router(user.router)
app.include_router(authentication.router)
app.include_router(blog.router)
app.include_router(admin.router)

@app.get("/",tags=["Home page"])
def root():
    return {"message": "Hello World"}

 

從我的共享軟管移動到 aws ec2 后,我的快速 api 應用程序運行良好。 所以你不能在低配置共享主機上運行你的 fastapi 應用程序。 您的 vps 主機至少需要 1 GB 的內存和 2 個 cpu 內核才能順利運行快速的 api 應用程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM