i具有接收文件,将其保存在本地,将其保存并将未纠正的图像推入伪影位置的FastApi函数。由于某种原因,较大的文件或有时较小的文件,在上传
200
响应时会计时。我似乎也遵循所有建议,但也没有运气!
nginx
我的nginx注释是我的nginx。
@router.post("/upload_container")
async def post_container(file: UploadFile = File(), new_container_image: str = Form(), new_tag: str = Form()):
if file.content_type != "application/x-tar":
raise HTTPException(status_code=400, detail="Can only accept tarred version of Docker file")
file_path = str(str(uuid.uuid4()).split("-")[1]) + ".tar"
async with aiofiles.open(file_path, "wb") as out_file:
while content := await file.read(1024): # async read chunk
await out_file.write(content) # async write chunk
file_path = str(os.path.abspath(os.path.join(os.getcwd(), file_path)))
command = "podman load --input {}".format(file_path)
result = subprocess.run(split(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode != 0:
return {"filename": file.filename, "details": result.stderr, "Error": {" failed to unwrap"}}
tagged_image = str(str(result.stdout).split("\n")[0]).split("Loaded image(s):")[1]
if os.path.exists(file_path):
os.remove(file_path)
if tagandpull(tagged_image, new_container_image, new_tag) != True:
return {"message": "Unable to push the image", "image_name": f"{file.filename}"}
return {
"filename": file.filename,
"Details": {
"new_url": "artifactorylocation.cloud.com/"
+ config_data.output["repos"]["local"]["deploy_repo"]
+ "/"
+ new_container_image,
"new_tag": new_tag,
},
}
以前有人遇到过这个问题吗?
您在请求处理程序中仍在做很多事情,这些事情仅比合理的HTTP超时了。
也许您可以将传入的请求从操作中解除,因此传入请求设置了一个由服务进行轮询的标志,该服务是在请求之外进行工作的服务。
您应该查看this this Answer
faster
使用 annotations: {
'kubernetes.io/ingress.class': 'nginx',
'nginx.ingress.kubernetes.io/proxy-body-size': '2400m',
'nginx.ingress.kubernetes.io/proxy-connect-timeout': '600',
'nginx.ingress.kubernetes.io/proxy-read-timeout': '600',
'nginx.ingress.kubernetes.io/proxy-send-timeout': '600'
},
UploadFile
(请参阅thisAnswer)或幕后的一个(请参阅this Ansion)。使用这些方法可以显着最大程度地减少调用您定义的端点所需的时间,并通过服务器获得响应。因此,避免任何超时。响应可以将唯一的参考ID返回到客户端,以查询其请求状态(即文件仍在待处理,正在处理或完成处理),以及获取任何相关结果。
您总是可以增加BackgroundTask
值,该值(对于
ProcessPool
)默认值为秒秒,如documentation:
:
/upload_container
-紧密的静脉连接,如果在此超时内未收到新数据。 默认:5.
例如,从命令行划出
timeout
:
uvicorn
以编程方式互动,例如:
5