From 1a8536fd5d9c3c05a0c4b5cd0e6e4a502c9c53bc Mon Sep 17 00:00:00 2001 From: Andrii Ostapenko Date: Fri, 29 May 2020 13:36:18 -0500 Subject: [PATCH] Explicitly set number of schedulers for Erlang VM By default erlang VM determines a number of scheduler threads equal to a number of CPU cores it detects [0]. Running rabbitmq in container makes Erlang VM to think it has all host CPU power, making extra scheduler threads competing for CPU time and, depending on a difference between a number host CPU cores and container limits, causing CPU throttling even while idle. This commit limits a number of schedulers to a value actually available to container via k8s resource limits (min 1) emulating the default behavior. [0] https://www.rabbitmq.com/runtime.html#scheduling Change-Id: If36f63173de4c8035daf7aac4014c027c579b58f --- rabbitmq/templates/statefulset.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rabbitmq/templates/statefulset.yaml b/rabbitmq/templates/statefulset.yaml index 71134f2a1..99f5d3e8c 100644 --- a/rabbitmq/templates/statefulset.yaml +++ b/rabbitmq/templates/statefulset.yaml @@ -12,6 +12,23 @@ See the License for the specific language governing permissions and limitations under the License. */}} +{{/* +(aostapenko) rounds cpu limit in any permissible format to integer value (min 1) +"100m" -> 1 +"1100m" -> 1 +"10900m" -> 10 +0.3 -> 1 +5.4 -> 5 +*/}} +{{- define "get_erlvm_scheduler_num" -}} +{{- $val := . | toString -}} +{{- if regexMatch "^[0-9]*m$" $val -}} +{{- $val = div (float64 (trimSuffix "m" $val)) 1000 -}} +{{- end -}} +{{/* NOTE(aostapenko) String with floating number does not convert well to int*/}} +{{- $val | float64 | int | default 1 -}} +{{- end -}} + {{- if .Values.manifests.statefulset }} {{- $envAll := . }} @@ -190,6 +207,9 @@ spec: value: "{{ tuple "oslo_messaging" "internal" "amqp" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}" - name: PORT_CLUSTERING value: "{{ add (tuple "oslo_messaging" "internal" "amqp" . | include "helm-toolkit.endpoints.endpoint_port_lookup") 20000 }}" + - name: RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS + {{- $erlvm_scheduler_num := include "get_erlvm_scheduler_num" .Values.pod.resources.server.limits.cpu }} + value: {{ printf "+S %s:%s" $erlvm_scheduler_num $erlvm_scheduler_num | quote }} readinessProbe: initialDelaySeconds: 10 timeoutSeconds: 10