From 07c529555edefb64b07a5a1c1e40b932c5417ded Mon Sep 17 00:00:00 2001 From: Nick Carboni Date: Thu, 4 Jun 2020 10:52:12 -0400 Subject: [PATCH] Change cpu threshold to a percent --- app/models/miq_worker/container_common.rb | 7 +++++-- config/settings.yml | 2 +- spec/models/miq_worker/container_common_spec.rb | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/models/miq_worker/container_common.rb b/app/models/miq_worker/container_common.rb index 32256e57730..fc25c12a930 100644 --- a/app/models/miq_worker/container_common.rb +++ b/app/models/miq_worker/container_common.rb @@ -33,13 +33,16 @@ def zone_selector def resource_constraints mem_threshold = self.class.worker_settings[:memory_threshold] - cpu_threshold = self.class.worker_settings[:cpu_threshold] + cpu_threshold = self.class.worker_settings[:cpu_threshold_percent] return {} if !Settings.server.worker_monitor.enforce_resource_constraints || (mem_threshold.nil? && cpu_threshold.nil?) {:limits => {}}.tap do |h| h[:limits][:memory] = "#{mem_threshold / 1.megabyte}Mi" if mem_threshold - h[:limits][:cpu] = "#{cpu_threshold}m" if cpu_threshold + if cpu_threshold + millicores = ((cpu_threshold / 100.0) * 1000).to_i + h[:limits][:cpu] = "#{millicores}m" + end end end diff --git a/config/settings.yml b/config/settings.yml index 110f9e3fe2b..b22751ca711 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1070,7 +1070,7 @@ :worker_base: :defaults: :count: 1 - :cpu_threshold: 500 + :cpu_threshold_percent: 50 :gc_interval: 15.minutes :heartbeat_freq: 10.seconds :heartbeat_timeout: 2.minutes diff --git a/spec/models/miq_worker/container_common_spec.rb b/spec/models/miq_worker/container_common_spec.rb index 8421fa36369..6a537d30f80 100644 --- a/spec/models/miq_worker/container_common_spec.rb +++ b/spec/models/miq_worker/container_common_spec.rb @@ -103,7 +103,7 @@ def deployment_name_for(name) end it "returns the correct hash when both values are set" do - allow(MiqGenericWorker).to receive(:worker_settings).and_return(:memory_threshold => 500.megabytes, :cpu_threshold => 500) + allow(MiqGenericWorker).to receive(:worker_settings).and_return(:memory_threshold => 500.megabytes, :cpu_threshold_percent => 50) constraints = { :limits => { :memory => "500Mi", @@ -124,10 +124,10 @@ def deployment_name_for(name) end it "returns only cpu when cpu is set" do - allow(MiqGenericWorker).to receive(:worker_settings).and_return(:cpu_threshold => 500) + allow(MiqGenericWorker).to receive(:worker_settings).and_return(:cpu_threshold_percent => 80) constraints = { :limits => { - :cpu => "500m" + :cpu => "800m" } } expect(MiqGenericWorker.new.resource_constraints).to eq(constraints) @@ -138,7 +138,7 @@ def deployment_name_for(name) before { stub_settings(:server => {:worker_monitor => {:enforce_resource_constraints => false}}) } it "always returns an empty hash" do - allow(MiqGenericWorker).to receive(:worker_settings).and_return(:memory_threshold => 500.megabytes, :cpu_threshold => 500) + allow(MiqGenericWorker).to receive(:worker_settings).and_return(:memory_threshold => 500.megabytes, :cpu_threshold => 50) expect(MiqGenericWorker.new.resource_constraints).to eq({}) end end