我有以下程序结构。
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
启用了Celluloid类。这很好用,直到我尝试循环执行程序。我需要根据从外部数据馈送接收的参数数量动态调整工作池大小。
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
的循环中,但它是垃圾邮件线程并导致玩家崩溃。
答案 0 :(得分:0)
设置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