【发布时间】:2020-10-22 18:46:38
【问题描述】:
我希望创建一个接收请求、进行一些处理并将请求转发到另一个端点的服务器。我似乎遇到了更高并发的问题,我的client.post 导致httpx.ConnectTimeout 异常。
我还没有完全排除端点出现问题的可能性(我目前正在与他们合作调试任何可能出现在他们身上的东西),但我正在尝试找出是否有问题我的结局,或者如果有任何明显的低效率我可以改进。
我在 ECS 中运行它,目前在一个任务有 4 个 vCPU 的集群上。我正在使用泊坞窗图像uvicorn-gunicorn-fastapi(https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker)。目前所有默认设置减去绑定/端口/日志记录。这是一个最小的代码示例:
import httpx
from fastapi import FastAPI, Request, Response
app = FastAPI()
def process_request(path, request):
#Process Request Here
def create_headers(path):
#Create headers here
@app.get('/')
async def root(path: str, request: Request):
endpoint = 'https://endpoint.com/'
querystring = 'path=' + path
data = process_request(request, path, request)
headers = create_headers(request)
async with httpx.AsyncClient() as client:
await client.post(endpoint + "?" + querystring, data=data, headers=headers)
return Response(status_code=200)
【问题讨论】:
标签: python python-3.x fastapi httpx