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
This commit is contained in:
Andrii Ostapenko 2020-05-29 13:36:18 -05:00
parent b19c7f21c9
commit 1a8536fd5d

View File

@ -12,6 +12,23 @@ See the License for the specific language governing permissions and
limitations under the License. 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 }} {{- if .Values.manifests.statefulset }}
{{- $envAll := . }} {{- $envAll := . }}
@ -190,6 +207,9 @@ spec:
value: "{{ tuple "oslo_messaging" "internal" "amqp" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}" value: "{{ tuple "oslo_messaging" "internal" "amqp" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}"
- name: PORT_CLUSTERING - name: PORT_CLUSTERING
value: "{{ add (tuple "oslo_messaging" "internal" "amqp" . | include "helm-toolkit.endpoints.endpoint_port_lookup") 20000 }}" 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: readinessProbe:
initialDelaySeconds: 10 initialDelaySeconds: 10
timeoutSeconds: 10 timeoutSeconds: 10