1

我想我对赛璐珞池的理解有点被打破了。我将尝试在下面解释,但在此之前快速说明。

注意:我们的系统是针对fast client通过 ZeroMQ 传递的消息运行的。

使用以下香草赛璐珞应用程序

class VanillaClient
   include Celluloid::ZMQ

   def read
      loop { async.evaluate_response(socket.read_multipart)
   end

   def evaluate_response(data)
      ## the reason for using defer can be found over here.

      Celluloid.defer do 
        ExternalService.execute(data)
      end
   end
end

我们的系统在一段时间后导致失败,原因 'Can't spawn more thread'(或类似的东西)

所以我们打算使用赛璐珞池(避免上述问题),这样我们就可以限制产生的线程数

我对赛璐珞池的理解是赛璐珞池为你维护了一个演员池,这样你就可以并行分配你的任务。

因此,我决定对其进行测试,但根据我的测试用例,它似乎是串行的(即事情永远不会分发或并行发生。)

复制此示例。

sender-1.rb

## Send message `1` to the the_client.rb

sender-2.rb

## Send message `2` to the the_client.rb

the_client.rb

## take message from sender-1 and sender-2 and return it back to receiver.rb
## heads on, the `sleep` is introduced to test/replicate the IO block that happens in the actual code.

receiver.rb

## print the message obtained from the_client.rb

如果,sender-2.rbsender-1.rb使用由20_ _the_client.rbsender-1.rb

它在 ruby​​-2.2.2 和 jRuby-9.0.5.0 下的行为相同。池以这种方式行事的可能原因是什么?

4

1 回答 1

0

您的pool呼叫不是异步的。

evaluate与原始示例一样, on的执行@pool需要保持.async不动,而不是使用池。您仍然需要异步行为,但您也希望拥有多个处理程序参与者。


接下来,您可能会遇到Pool.async错误。

这意味着在池中的至少一个演员完成之前,您的池中的5点击后将变得无响应。evaluate最坏的情况是,如果您6+连续快速收到请求,6th则将需要120几秒钟,因为它需要5*20几秒钟才能执行,然后20几秒钟才能执行自身。


根据您的实际操作是什么导致您延迟 - 您可能需要调整您的池大小。

于 2016-03-12T03:21:34.440 回答