2017-07-05 71 views
0

我有以下程序結構。賽璐珞調整大小池

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。這很有效,直到我嘗試在循環中執行程序。我需要根據從外部數據饋送收到的參數數量動態調整工作人員的大小。

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

設置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