- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Java Spring Boot 开发人员,我开发 3 层 CRUD 应用程序。我和一个似乎对这个问题很了解的人交谈过,但我没有得到他的联系方式。他提倡 Python 的 FastApi,因为它的横向扩展比 Spring boot 更好。他提到的原因之一是 FastApi 是单线程的。当线程遇到数据库查找(或其他可以异步完成的工作)时,它会选择其他工作,以便稍后在数据库结果输入时返回到当前工作。在 Java 中,当有许多请求挂起时,线程游泳池可能会耗尽。
我 100% 不明白这个推理。让我扮演魔鬼的代言人。当 Python 程序遇到异步调用时,它必须以某种方式将程序指针存储在某个地方,以记住它需要在何处继续。我知道存储程序指针的那个地方根本不是线程,但我必须给它起个名字,所以我们称它为“逻辑线程”。在 Python 中,您可以有许多等待的逻辑线程。在 Java 中,您可以拥有一个包含许多正在等待的真实线程的线程池。对我来说,唯一的区别似乎是 Java 的线程是在操作系统级别管理的,而 Python 的“逻辑线程”是由 Python 或 FastApi 管理的。为什么在线程池中等待的真实线程比等待的逻辑线程要昂贵得多?如果我的大部分线程都在等待,为什么我不能增加线程池大小以避免耗尽?
最佳答案
问题中 Java 线程的问题由 Loom 项目解决,该项目计划包含在未来的 Jdk 中。这里解释得很好https://www.baeldung.com/openjdk-project-loom :
Presently, Java relies on OS implementations for both the continuation [of threads] and the scheduler [for threads].
Now, in order to suspend a continuation, it's required to store the entire call-stack. And similarly, retrieve the call-stack on resumption. Since the OS implementation of continuations includes the native call stack along with Java's call stack, it results in a heavy footprint.
A bigger problem, though, is the use of OS scheduler. Since the scheduler runs in kernel mode, there's no differentiation between threads. And it treats every CPU request in the same manner. (...)For example, consider an application thread which performs some action on the requests and then passes on the data to another thread for further processing. Here, it would be better to schedule both these threads on the same CPU. But since the [OS] scheduler is agnostic to the thread requesting the CPU, this is impossible to guarantee.
关于python - Java Spring Boot 与 Python FastApi : Threads,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73026698/
我正在研究最适合我的 Web 框架。 我们将开发几个微服务,我们需要在一些微服务上分派(dispatch)事件,这些事件可以在其他微服务上监听。 是否支持使用 FastAPI?如果没有,有没有办法监听
快速API 0.68.0 python 3.8 from fastapi import Depends, FastAPI, Header, HTTPException async def verify
在 FastAPI 框架内: 虽然请求数据当然可以作为参数传递,但我想知道函数是否可以在不传递参数的情况下访问有关当前请求的信息。 免责声明:我不认为全局访问请求数据是一个好的做法,但我有一个用例,如
无论如何,FastAPI“依赖项”是否可以解释路径参数。 我有很多形式的功能: @app.post("/item/{item_id}/process", response_class=ProcessR
我有一个由诗歌构建的 fastapi 项目。我想使用 pyproject.tom 中的脚本部分运行应用程序,如下所示: poetry run start 该部分的双引号内是什么? [tool.poet
我正在尝试将分页添加到我的 fastapi 项目中。所以我决定使用这个: fastapi-contrib 我在那里遵循相同的示例,但由于某种原因我收到此错误: type object 'MOrdene
在我的项目文件夹中,我有一个基本的 index.html文件加上静态文件(js、css)以及我的 main.py : from fastapi.staticfiles import StaticFil
FastAPI显示可以设置response_model_exclude_none=True在装饰器中忽略值为 None 的字段:https://fastapi.tiangolo.com/tutoria
FastAPI 生成自动 swagger/openapi 文档。 在 https://fastapi.tiangolo.com/tutorial/response-status-code 的教程中有一
我获得了使用FastApi运行推理服务器的以下代码。在大约8小时内,我的RAM内存增加了4Gi。。更有趣的是,当我停止我的容器时,内存并没有清理干净。。例如,在运行Docker Container之前
今天的文章分享如下在 FastAPI 框架下,使用 pytest 来自动化测试数据库相关的接口,文章的最后给出全部代码。 最近越来越喜欢使用 FastAPI 来写后端服务了,因为它是 Pyth
Docker 学习 https://www.cnblogs.com/poloyy/p/15257059.html 项目结构 .├── app│ ├── __init__.py│ └
下面代码来自官方FastAPI tutorials page ,我无法理解这些语句(例如,name: str)。 from typing import Optional from fastapi im
我是网络通信的新手。我使用 ubuntu 并尝试学习 fastapi。但是,我认为很难理解如何格式化我打算发送回客户端的响应。 要发回的响应的规则是什么?如果您想发回自定义答案 - 例如两个图像文件
我正在尝试从文件中添加路由,但我事先并不知道实际的参数,因此我需要一个通用函数来通过 **kwargs 处理参数。 要添加路由,我正在使用 add_api_route,如下所示: from fasta
我按照此文档设置了一个用户: https://fastapi.tiangolo.com/advanced/security/http-basic-auth/ 但我只收到一个端点“/users/me”的
当我尝试从我的 postgre 数据库中获取一些数据并使用 fastapi 时出现此错误。 我不知道为什么会这样......但这是我的代码,谢谢你的帮助。 路线 @router.get("/fuent
我有一个与在 pycharm 中使用 uvicorn 的 FastAPI 有关的问题。我的项目具有以下结构: LearningPy | |-- apis -----|--modelser
我已经创建了一个登录路径,我在其中发布了我的表单数据并设置了一个 cookie。设置 cookie 后,我重定向到“/main”,在那里我得到 {detail:"Method Not Allowed"
当我使用 FastAPI 时,如何为网络服务指定基本路径? 换句话说 - FastAPI 对象是否有参数可以将端点和我定义的任何其他对象设置为不同的根路径? 例如,如果我的代码带有下面的虚假参数 ro
我是一名优秀的程序员,十分优秀!