refill Docker container pool in small batches
This commit is contained in:
@ -2,7 +2,8 @@ default: &default
|
|||||||
connection_timeout: 3
|
connection_timeout: 3
|
||||||
pool:
|
pool:
|
||||||
active: false
|
active: false
|
||||||
interval: 60
|
interval: 15
|
||||||
|
maximum_refill_count: 32
|
||||||
ports: !ruby/range 4500..4600
|
ports: !ruby/range 4500..4600
|
||||||
|
|
||||||
development:
|
development:
|
||||||
|
@ -36,7 +36,7 @@ class DockerContainerPool
|
|||||||
|
|
||||||
def self.refill
|
def self.refill
|
||||||
ExecutionEnvironment.all.each do |execution_environment|
|
ExecutionEnvironment.all.each do |execution_environment|
|
||||||
refill_count = execution_environment.pool_size - @containers[execution_environment.id].length
|
refill_count = [execution_environment.pool_size - @containers[execution_environment.id].length, config[:maximum_refill_count]].min
|
||||||
if refill_count > 0
|
if refill_count > 0
|
||||||
Concurrent::Future.execute do
|
Concurrent::Future.execute do
|
||||||
@containers[execution_environment.id] += refill_count.times.map { create_container(execution_environment) }
|
@containers[execution_environment.id] += refill_count.times.map { create_container(execution_environment) }
|
||||||
|
@ -91,7 +91,16 @@ describe DockerContainerPool do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with something to refill' do
|
context 'with something to refill' do
|
||||||
before(:each) { @execution_environment.update(pool_size: 1) }
|
let(:maximum_refill_count) { 5 }
|
||||||
|
before(:each) { @execution_environment.update(pool_size: 10) }
|
||||||
|
|
||||||
|
it 'complies with the maximum batch size' do
|
||||||
|
expect(DockerContainerPool::config).to receive(:[]).with(:maximum_refill_count).and_return(maximum_refill_count)
|
||||||
|
expect_any_instance_of(Concurrent::Future).to receive(:execute) do |future|
|
||||||
|
expect(DockerContainerPool).to receive(:create_container).with(@execution_environment).exactly(maximum_refill_count).times
|
||||||
|
future.instance_variable_get(:@task).call
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'works asynchronously' do
|
it 'works asynchronously' do
|
||||||
expect(Concurrent::Future).to receive(:execute)
|
expect(Concurrent::Future).to receive(:execute)
|
||||||
|
Reference in New Issue
Block a user