简体   繁体   English

使用Akka并行进行实时计算

[英]Using akka to do real time computation in parallel

I have a use case as follows: 我有一个用例如下:

I need to split my computation among multiple threads and all threads needs to send back the results to master thread in quick time. 我需要将计算分配到多个线程中,并且所有线程都需要将结果尽快发送回主线程。

Flow

  1. There is a search query which is entered by user 用户输入了一个搜索查询
  2. Query comes to akka 查询到akka
  3. Query needs to be distributed among number of akka actors . 查询需要在多个Akka参与者之间分配。
  4. Each akka actor will do some kind of processing and return a results to parent actor 每个akka演员都会进行某种处理,并将结果返回给父演员

But each akka actor is single threaded. 但是每个akka演员都是单线程的。 And I have multiple queries coming at the same time. 而且我同时遇到多个查询。

How can I serve multiple queries in quick time without making any query to wait on its computation. 如何快速处理多个查询,而无需进行任何查询来等待其计算。

Is akka suitable for this use case? Akka是否适合此用例? If yes how can I model it? 如果是,我该如何建模?

Akka is perfectly suited to this kind of application! Akka非常适合这种应用!

t is true that each actor is single threaded. 每个actor是单线程的是正确的。 That is, each actor processes its own messages sequentially (one at a time) and synchronously (single threaded). 即,每个参与者依次(一次一个)和同步(单线程)处理自己的消息。 But you're free to create as many actors as you'd like, and those actors operate completely asynchronously from each other. 但是您可以自由创建任意数量的actor,并且这些actor彼此完全异步运行。

In other words, you can spawn a new actor for each query request. 换句话说,您可以为每个查询请求生成一个新的参与者。 Each actor handles a single request in a safe, single threaded fashion, but as a whole you're handling multiple queries simultaneously. 每个参与者都以安全,单线程的方式处理单个请求,但总体而言,您要同时处理多个查询。

For the use case you've described, I'd look into using akka-io for your IO layer and something like the balancing dispatcher pattern to divide the queries among workers. 对于您所描述的用例,我将研究在您的IO层中使用akka-io以及诸如平衡调度程序模式之类的方法来在工作人员之间划分查询。

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

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