简体   繁体   English

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

[英]Should multithreading be used in microservices?

Should parallel programming be used in the development of microservices in case the microservices are scalable and, for instance, deployed as ECS on AWS?如果微服务是可扩展的,例如在 AWS 上部署为 ECS,是否应该在微服务的开发中使用并行编程?

If yes, what are the benefits of consuming more resources by one instance vs the same resources by N instances?如果是,一个实例消耗更多资源与 N 个实例消耗相同资源的好处是什么?

How does parallel programming match https://12factor.net/并行编程如何匹配https://12factor.net/

PS to be more specific - should I conceptually use parallel streams rather than simple streams? PS更具体 - 我应该在概念上使用并行流而不是简单的流吗?

Basically the link that you provided also provides answer to your question already基本上您提供的链接也已经为您的问题提供了答案

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.这并不排除单个进程通过运行时 VM 内的线程或在 EventMachine、Twisted 或 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.但是单个 VM 只能增长到如此大(垂直规模),因此应用程序还必须能够跨越在多个物理机器上运行的多个进程。

https://12factor.net/concurrency https://12factor.net/concurrency

Sure, imagine a microservice that needs to execute multiple independent calls to a dB or to other microservice and aggregate the results.当然,想象一个微服务需要对 dB 或其他微服务执行多个独立调用聚合结果。 As the calls are independent, they can be executed in parallel so that the total time is at most the time it takes to execute the slowest call.由于调用是独立的,它们可以并行执行,因此总时间最多是执行最慢调用所需的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM