知识卡片
异步入口不会自动并行同步推理
async函数里直接调用同步CPU推理,仍可能阻塞事件循环。并发方案需匹配计算与I/O特点,按框架使用线程、进程或任务队列等方式;仅加async关键字不能证明服务可承受更多用户。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
@app.post("/intent/", response_model=Response) async def intent(request: Request): #1 response = Response() response.tags = predict_intents(request.text) response.created_at = datetime.now() return response #1 To improve readability, use the same name for the endpoint function and the endpoint URL path. The endpoint function receives a Request object and uses it to construct a Response object. The app.post decorator takes care of all the HTTP POST protocol processing to convert the
参考来源
- 位置:《Natural Language Processing in Action, Second Edition》附录E《附录E:容器化微服务部署》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/appendix-e.html)
- 结论依据:摘录中关于异步入口不会自动并行同步推理的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:@app.post("/intent/", response_model=Response) async def intent(request: Request): #1 response = Response() response.tags = predict_intents(request.text) response.created_at = datetime.now() return response #1 To improve readability, use the same name for the endpoint function and the endpoint URL path. The endpoint function receives a Request object and uses it to construct a Response object. The app.post decorator takes care of all the HTTP POST protocol processing to convert the