应该在微服务中使用多线程吗?

Should multithreading be used in microservices?

如果微服务是可扩展的,例如在 AWS 上部署为 ECS,是否应该在微服务开发中使用并行编程?

如果是,一个实例消耗更多资源与 N 个实例消耗相同资源有什么好处?

并行编程如何匹配https://12factor.net/

P.S。更具体地说 - 我应该在概念上使用并行流而不是简单流吗?

基本上您提供的 link 也已经为您的问题提供了答案

This does not exclude individual processes from handling their own internal multiplexing, via threads inside the runtime VM, or the async/evented model found in tools such as EventMachine, Twisted, or Node.js. But an individual VM can only grow so large (vertical scale), so the application must also be able to span multiple processes running on multiple physical machines.

https://12factor.net/concurrency

当然,想象一个微服务需要对 dB 或其他微服务执行多个独立调用 聚合结果。由于调用是独立的,它们可以并行执行,因此总时间最多是执行最慢调用所花费的时间。

当手头的任务相互排斥并且可以并行完成时,必须使用并行流。然而,并行编程伴随着使用更多资源的开销。所以根据手头的任务,你需要用trade-offs做出决定,这对你来说是最好的。