Serverless 上的并发(比如 Google Cloud 运行)毫无意义吗?

Is concurrency on Serverless (like Google Cloud Run) pointless?

据我所知,默认情况下,在 Google Cloud 上以及大概在其他地方,每个 vCPU = 1 hyperthread. (3rd paragraph in the intro) Which, from my perspective, would suggest that unless one changes this setting to 2 or 4 vCPUs, concurrency in the code running on the docker image achieves nothing. Is there some multi-threaded knowledge im missing that means that concurrency on a single hyperthread accomplishes something? scaling up the vCPU number isnt very attractive as the minimum memory setting is already forced to 2GB for 4 vCPUs

此问题是基于 Google 云技术栈设计的,但旨在涵盖所有提供商。

无服务器解决方案真的能从并发中受益吗?

编辑:

接受的答案初看起来很棒,但我意识到我的上述假设忽略了上下文切换空闲时间。例如:

如果我们希望编写一个与数据库对话的后端,我们的大量计算时间可能会花在等待数据库请求结果上。在这种情况下,上下文切换到下一个请求将使我们能够更有效地填充 CPU 负载。

因此,根据用例,即使在单线程 vCPU 上,我们的无服务器应用程序也可以从并发性中受益

我写了this。根据我的经验,是的,您可以并行处理多个线程,并且性能会随着 CPU 的数量而增加。但是,你需要有一个支持多线程的进程。

如果是 Cloud 运行,每个请求都可以在一个线程中处理,并行化很容易。