【发布时间】:2021-07-30 10:23:32
【问题描述】:
根据线程标题,给定以下 API:
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*'],
)
app.mount("/app/static", StaticFiles(directory="app/static"), name="static")
@app.post("/")
async def get_text(image: UploadFile = File(...)):
temp_file = _save_file_to_disk(image, path="app/static/", save_as="temp")
text = await ocr(temp_file)
return {"text": text}
和下面的 Gunicorn 命令来启动应用程序:
CMD ["gunicorn", "app:app", "-w", "4", "--threads", "12", "--timeout", "120",
"--bind", "0.0.0.0:8080", "-k","uvicorn.workers.UvicornWorker", "--worker-connections", "1000"]
如果 3 个不同的请求同时由 3 个不同的用户发送,第一个用户的结果会超过第二个和第三个用户的结果
【问题讨论】:
标签: python-3.x concurrency load-balancing gunicorn fastapi