赛璐珞调整池

Celluloid resize pool

我有以下程序结构。

client = Client.new
params = client.get_params
pool = client.pool(size: params.size)

futures = params.map do |p|
    pool.future(:perform_work, p)
end

futures.map(&:value)

客户端使用 include Celluloid 启用赛璐珞 class。在我尝试循环执行程序之前,这很好用。我需要根据从外部数据源接收到的参数数量动态调整工作人员池的大小。

client = Client.new
pool = client.pool(size: 1)

loop do
   params = client.get_params

   ....
   **? pool.resize(size: params.size) ?**
   ....

   futures = params.map do |p|
      pool.future(:perform_work, p)
   end

   futures.map(&:value)
   sleep 1
end

我尝试将池创建包含到循环中,随后 pool.terminate 但它是垃圾线程并导致 actor 崩溃。

设置 pool.size 似乎有效

client = Client.new
pool = client.pool(size: 1)

loop do
   params = client.get_params
   pool.size = params.size

   futures = params.map do |p|
      pool.future(:perform_work, p)
   end

   futures.map(&:value)
   sleep 1
end