[英]Getting connection error if made httprequest from my production server to other production server , but its done with localhost
[英]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.