Skip to content

Commit 2eca4bb

Browse files
committed
feat(chart): Configure fixed-sized thread pool for the Distributor in autoscaling
Configure fixed-sized thread pool for the Distributor to create new sessions based on sum of maxReplicaCount of all enabled Nodes in autoscaling Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 97941f8 commit 2eca4bb

13 files changed

+86
-27
lines changed

Diff for: .github/workflows/helm-chart-test.yml

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
description: 'Test parameter for different request timeout'
1616
required: false
1717
default: '370'
18+
max-replicas-count:
19+
description: 'Test parameter for autoscaling to set maxReplicaCount'
20+
required: false
21+
default: '30'
1822
log-level:
1923
description: 'Test parameter for different log level'
2024
required: false
@@ -116,8 +120,11 @@ jobs:
116120
if: (matrix.test-strategy == 'job' || matrix.test-strategy == 'deployment') && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
117121
run: |
118122
echo "AUTOSCALING_POLL_INTERVAL=${AUTOSCALING_POLL_INTERVAL}" >> $GITHUB_ENV
123+
echo "SET_MAX_REPLICAS=${SET_MAX_REPLICAS}" >> $GITHUB_ENV
124+
echo "LOG_LEVEL=${LOG_LEVEL}" >> $GITHUB_ENV
119125
env:
120126
AUTOSCALING_POLL_INTERVAL: ${{ github.event.inputs.request-timeout || '370' }}
127+
SET_MAX_REPLICAS: ${{ github.event.inputs.max-replicas-count || '30' }}
121128
LOG_LEVEL: ${{ github.event.inputs.log-level || 'FINE' }}
122129
- name: Test Selenium Grid on Kubernetes ${{ matrix.k8s-version }} with Autoscaling ${{ matrix.test-strategy }}
123130
uses: nick-invision/retry@master

Diff for: charts/selenium-grid/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This chart enables the creation of a Selenium Grid Server in Kubernetes.
1414
* [Settings common for both `job` and `deployment` scalingType](#settings-common-for-both-job-and-deployment-scalingtype)
1515
* [Settings when scalingType with `deployment`](#settings-when-scalingtype-with-deployment-)
1616
* [Settings when scalingType with `job`](#settings-when-scalingtype-with-job)
17+
* [Settings fixed-sized thread pool for the Distributor to create new sessions](#settings-fixed-sized-thread-pool-for-the-distributor-to-create-new-sessions)
1718
* [Updating Selenium-Grid release](#updating-selenium-grid-release)
1819
* [Uninstalling Selenium Grid release](#uninstalling-selenium-grid-release)
1920
* [Ingress Configuration](#ingress-configuration)
@@ -195,6 +196,16 @@ autoscaling:
195196

196197
Settings that KEDA [ScaledJob spec](https://keda.sh/docs/latest/concepts/scaling-jobs/#scaledjob-spec) supports can be set via `autoscaling.scaledJobOptions`.
197198

199+
### Settings fixed-sized thread pool for the Distributor to create new sessions
200+
201+
When enabling autoscaling, the Distributor might be under a high workload with parallelism tests, which are many requests incoming and nodes scaling up simultaneously. (Refer to: [SeleniumHQ/selenium#13723](https://github.com/SeleniumHQ/selenium/issues/13723)).
202+
203+
By default, the Distributor uses a fixed-sized thread pool with default value is `no. of available processors * 3`.
204+
205+
In autoscaling, by default, it will calculate based on `no. of node types * maxReplicaCount`. For example: `autoscaling.scaledOptions.maxReplicaCount=50`, 3 node types (`Chrome, Firefox, Edge` enabled), the value is `50 * 3 + 1 = 151` is set to environment variable `SE_NEW_SESSION_THREAD_POOL_SIZE` to adjust the Distributor config `--newsession-threadpool-size`
206+
207+
You can override the default calculation by another value via `components.distributor.newSessionThreadPoolSize` (in full distributed mode) or `hub.newSessionThreadPoolSize` (in basic mode).
208+
198209
## Updating Selenium-Grid release
199210

200211
Once you have a new chart version, you can update your selenium-grid running:

Diff for: charts/selenium-grid/templates/_helpers.tpl

+21
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ Is tracing enabled
127127
{{- or .Values.tracing.enabled .Values.tracing.enabledWithExistingEndpoint | ternary "true" "" -}}
128128
{{- end -}}
129129

130+
{{/*
131+
Configure fixed-sized thread pool for the Distributor to create new sessions
132+
based on sum of maxReplicaCount of all enabled Nodes in autoscaling
133+
*/}}
134+
{{- define "seleniumGrid.autoscaling.distributor.threadPoolSize" -}}
135+
{{- $threadPoolSize := 1 -}}
136+
{{- if .Values.chromeNode.enabled -}}
137+
{{- $maxReplicaCount := default .Values.autoscaling.scaledOptions.maxReplicaCount (.Values.chromeNode.scaledOptions).maxReplicaCount -}}
138+
{{- $threadPoolSize = add $threadPoolSize $maxReplicaCount -}}
139+
{{- end -}}
140+
{{- if $.Values.firefoxNode.enabled -}}
141+
{{- $maxReplicaCount := default .Values.autoscaling.scaledOptions.maxReplicaCount (.Values.firefoxNode.scaledOptions).maxReplicaCount -}}
142+
{{- $threadPoolSize = add $threadPoolSize $maxReplicaCount -}}
143+
{{- end -}}
144+
{{- if $.Values.edgeNode.enabled -}}
145+
{{- $maxReplicaCount := default .Values.autoscaling.scaledOptions.maxReplicaCount (.Values.edgeNode.scaledOptions).maxReplicaCount -}}
146+
{{- $threadPoolSize = add $threadPoolSize $maxReplicaCount -}}
147+
{{- end -}}
148+
{{- $threadPoolSize -}}
149+
{{- end -}}
150+
130151
{{/*
131152
Common autoscaling spec template
132153
*/}}

Diff for: charts/selenium-grid/templates/distributor-deployment.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ spec:
5252
value: '{{ template "seleniumGrid.sessionQueue.fullname" . }}.{{ .Release.Namespace }}'
5353
- name: SE_SESSION_QUEUE_PORT
5454
value: {{ .Values.components.sessionQueue.port | quote }}
55-
{{- with .Values.components.distributor.newSessionThreadPoolSize }}
55+
{{- if .Values.components.distributor.newSessionThreadPoolSize }}
5656
- name: SE_NEW_SESSION_THREAD_POOL_SIZE
57-
value: {{ . | quote }}
57+
value: {{ .Values.components.distributor.newSessionThreadPoolSize | quote }}
58+
{{- else if (eq (include "seleniumGrid.useKEDA" $) "true") }}
59+
- name: SE_NEW_SESSION_THREAD_POOL_SIZE
60+
value: '{{ template "seleniumGrid.autoscaling.distributor.threadPoolSize" $ }}'
5861
{{- end }}
5962
{{- with .Values.components.extraEnvironmentVariables }}
6063
{{- tpl (toYaml .) $ | nindent 12 }}

Diff for: charts/selenium-grid/templates/hub-deployment.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,12 @@ spec:
109109
- name: SE_DISABLE_UI
110110
value: {{ .Values.hub.disableUI | quote }}
111111
{{- end }}
112-
{{- with .Values.hub.newSessionThreadPoolSize }}
112+
{{- if .Values.hub.newSessionThreadPoolSize }}
113113
- name: SE_NEW_SESSION_THREAD_POOL_SIZE
114-
value: {{ . | quote }}
114+
value: {{ .Values.hub.newSessionThreadPoolSize | quote }}
115+
{{- else if (eq (include "seleniumGrid.useKEDA" $) "true") }}
116+
- name: SE_NEW_SESSION_THREAD_POOL_SIZE
117+
value: '{{ template "seleniumGrid.autoscaling.distributor.threadPoolSize" $ }}'
115118
{{- end }}
116119
{{- with .Values.hub.extraEnvironmentVariables }}
117120
{{- tpl (toYaml .) $ | nindent 12 }}

Diff for: charts/selenium-grid/values.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ chromeNode:
722722
url: '{{ template "seleniumGrid.graphqlURL" . }}'
723723
browserName: 'chrome'
724724
sessionBrowserName: 'chrome'
725-
platformName: 'Linux'
725+
platformName: 'linux'
726726
# browserVersion: '91.0' # Optional. Only required when supporting multiple versions of browser in your Selenium Grid.
727727
unsafeSsl: '{{ template "seleniumGrid.graphqlURL.unsafeSsl" . }}' # Optional
728728

@@ -883,7 +883,7 @@ firefoxNode:
883883
url: '{{ template "seleniumGrid.graphqlURL" . }}'
884884
browserName: 'firefox'
885885
sessionBrowserName: 'firefox'
886-
platformName: 'Linux'
886+
platformName: 'linux'
887887
unsafeSsl: '{{ template "seleniumGrid.graphqlURL.unsafeSsl" . }}' # Optional
888888

889889
# It is used to add initContainers in the same pod of the browser node.
@@ -1042,7 +1042,7 @@ edgeNode:
10421042
url: '{{ template "seleniumGrid.graphqlURL" . }}'
10431043
browserName: 'MicrosoftEdge'
10441044
sessionBrowserName: 'msedge'
1045-
platformName: 'Linux'
1045+
platformName: 'linux'
10461046
unsafeSsl: '{{ template "seleniumGrid.graphqlURL.unsafeSsl" . }}' # Optional
10471047

10481048
# It is used to add initContainers in the same pod of the browser node.

Diff for: tests/charts/ci/DeploymentAutoscaling-values.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ autoscaling:
33
scaledOptions:
44
minReplicaCount: 0
55
maxReplicaCount: 3
6-
pollingInterval: 20
6+
pollingInterval: 10
77
scaledObjectOptions:
88
cooldownPeriod: 30
99
terminationGracePeriodSeconds: 360

Diff for: tests/charts/ci/JobAutoscaling-values.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ autoscaling:
77
strategy: default
88
scaledOptions:
99
minReplicaCount: 0
10-
maxReplicaCount: 30
11-
pollingInterval: 20
10+
maxReplicaCount: 7
11+
pollingInterval: 10
1212
# Configuration for chrome nodes
1313
chromeNode:
1414
nameOverride: my-chrome-name

Diff for: tests/charts/ci/base-resources-values.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ components:
1010
distributor:
1111
resources:
1212
requests:
13-
cpu: 100m
14-
memory: 256Mi
13+
cpu: "1"
14+
memory: 1Gi
1515
limits:
16-
cpu: 200m
17-
memory: 2500Mi
16+
cpu: "2"
17+
memory: 2Gi
1818
eventBus:
1919
resources:
2020
requests:
@@ -43,11 +43,11 @@ components:
4343
hub:
4444
resources:
4545
requests:
46-
cpu: 100m
47-
memory: 256Mi
46+
cpu: "1"
47+
memory: 1Gi
4848
limits:
49-
cpu: 500m
50-
memory: 2500Mi
49+
cpu: "2"
50+
memory: 2Gi
5151

5252
chromeNode:
5353
resources:

Diff for: tests/charts/make/chart_test.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ if [ "${CHART_ENABLE_INGRESS_HOSTNAME}" = "true" ]; then
118118
if [[ ! $(cat /etc/hosts) == *"${HOSTNAME_ADDRESS}"* ]]; then
119119
sudo -- sh -c -e "echo \"$(hostname -i) ${HOSTNAME_ADDRESS}\" >> /etc/hosts"
120120
fi
121+
if [[ ! $(cat /etc/hosts) == *"alertmanager.${HOSTNAME_ADDRESS}"* ]]; then
122+
sudo -- sh -c -e "echo \"$(hostname -i) alertmanager.${HOSTNAME_ADDRESS}\" >> /etc/hosts"
123+
fi
124+
if [[ ! $(cat /etc/hosts) == *"grafana.${HOSTNAME_ADDRESS}"* ]]; then
125+
sudo -- sh -c -e "echo \"$(hostname -i) grafana.${HOSTNAME_ADDRESS}\" >> /etc/hosts"
126+
fi
127+
if [[ ! $(cat /etc/hosts) == *"pts.${HOSTNAME_ADDRESS}"* ]]; then
128+
sudo -- sh -c -e "echo \"$(hostname -i) pts.${HOSTNAME_ADDRESS}\" >> /etc/hosts"
129+
fi
121130
ping -c 2 ${HOSTNAME_ADDRESS}
122131
HELM_COMMAND_SET_IMAGES="${HELM_COMMAND_SET_IMAGES} \
123132
--set ingress.hostname=${HOSTNAME_ADDRESS} \
@@ -127,15 +136,6 @@ else
127136
HELM_COMMAND_SET_IMAGES="${HELM_COMMAND_SET_IMAGES} \
128137
--set global.K8S_PUBLIC_IP=${SELENIUM_GRID_HOST} \
129138
"
130-
if [[ ! $(cat /etc/hosts) == *"alertmanager.selenium-grid.prod"* ]]; then
131-
sudo -- sh -c -e "echo \"$(hostname -i) alertmanager.selenium-grid.prod\" >> /etc/hosts"
132-
fi
133-
if [[ ! $(cat /etc/hosts) == *"grafana.selenium-grid.prod"* ]]; then
134-
sudo -- sh -c -e "echo \"$(hostname -i) grafana.selenium-grid.prod\" >> /etc/hosts"
135-
fi
136-
if [[ ! $(cat /etc/hosts) == *"pts.selenium-grid.prod"* ]]; then
137-
sudo -- sh -c -e "echo \"$(hostname -i) pts.selenium-grid.prod\" >> /etc/hosts"
138-
fi
139139
fi
140140

141141
if [ "${CHART_ENABLE_BASIC_AUTH}" = "true" ]; then

Diff for: tests/charts/templates/render/dummy.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ components:
6868
"restartOnUpdate": "true"
6969
serviceType: NodePort
7070
distributor:
71+
newSessionThreadPoolSize: 24
7172
annotations:
7273
"restartOnUpdate": "true"
7374
serviceType: NodePort

Diff for: tests/charts/templates/render/dummy_solution.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ selenium-grid:
6767
disableUI: true
6868
serviceType: NodePort
6969
distributor:
70+
newSessionThreadPoolSize: 24
7071
serviceType: NodePort
7172
eventBus:
7273
serviceType: NodePort

Diff for: tests/charts/templates/test.py

+12
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ def test_sub_path_set_to_grid_env_var(self):
7373
is_present = True
7474
self.assertTrue(is_present, "ENV variable SE_SUB_PATH is not populated")
7575

76+
def test_distributor_new_session_thread_pool_size(self):
77+
resources_name = ['{0}selenium-distributor'.format(RELEASE_NAME)]
78+
is_present = False
79+
for doc in LIST_OF_DOCUMENTS:
80+
if doc['metadata']['name'] in resources_name and doc['kind'] == 'Deployment':
81+
logger.info(f"Assert newSessionThreadPoolSize is set to Distributor env SE_NEW_SESSION_THREAD_POOL_SIZE")
82+
list_env = doc['spec']['template']['spec']['containers'][0]['env']
83+
for env in list_env:
84+
if env['name'] == 'SE_NEW_SESSION_THREAD_POOL_SIZE' and env['value'] == '24':
85+
is_present = True
86+
self.assertTrue(is_present, "ENV variable SE_NEW_SESSION_THREAD_POOL_SIZE is not populated")
87+
7688
def test_disable_ui_set_to_grid_env_var(self):
7789
resources_name = ['{0}selenium-router'.format(RELEASE_NAME)]
7890
is_present = False

0 commit comments

Comments
 (0)