我有一组工人MessageConsumer
,每个人都有不同的职责:HTTP 调用、CRUD Mongo/Redis、API 调用等。
它们具有相同的结构:
class MessageConsumer
include Celluloid
def perform(sqs_message)
# Do something
end
end
我[worker-name].rb
为每个工人都有一个文件,其中包括:
Celluloid::Actor[:pool] = MessageConsumer.pool
while @still_running
sqs_message = @queue.receive_message(start_options)
if sqs_message
Celluloid::Actor[:pool].async.perform(sqs_message)
else
# sleep for a while as there's nothing in the queue.
sleep rand(2..6)
end
end
@queue.receive_message
接收来自 Amazon SQS 的消息并调用传递消息的工作人员。
在每台服务器中,我们都有一组[worker-name].rb
运行:
pgrep -fl ruby
14885 ruby bin/worker_http # two processes
15890 ruby bin/worker_http # ^^^
17956 ruby bin/worker_api
19734 ruby bin/worker_mongo
22637 ruby bin/worker_redis
问题:我"No live threads left. Deadlock?"
在运行进程一段时间后变得频繁(在让线程忙碌之后)。
我ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-linux]
在服务器中使用,不确定是否与 MRI 有关,也许我需要切换到 JRuby。但有趣的是,我认为这个问题并不常见,所以我认为这可能是我的实现问题。
有任何想法吗?