From 4145b71516b93043e9e5f1912baa8841f02a4e77 Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Sat, 26 Oct 2024 10:34:17 -0700 Subject: [PATCH 01/12] fix: misc 1. Helm Upgrade of crunchy 2. Memory adjustment for flyway to get rid of OOMKilled Signed-off-by: OMPRAKASH MISHRA --- .github/workflows/.dbdeployer.yml | 2 -- charts/app/templates/backend/templates/deployment.yaml | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/.dbdeployer.yml b/.github/workflows/.dbdeployer.yml index ab4b8390d..3daa2ab86 100644 --- a/.github/workflows/.dbdeployer.yml +++ b/.github/workflows/.dbdeployer.yml @@ -94,7 +94,6 @@ jobs: run: | echo 'Deploying crunchy helm chart' if [ ${{ inputs.s3_enabled }} == true ]; then - helm status postgres || \ helm upgrade --install --wait --set crunchy.pgBackRest.s3.enabled=true \ --set-string crunchy.pgBackRest.s3.accessKey=${{ secrets.s3_access_key }} \ --set-string crunchy.pgBackRest.s3.secretKey=${{ secrets.s3_secret_key }} \ @@ -102,7 +101,6 @@ jobs: --set-string crunchy.pgBackRest.s3.endpoint=${{ secrets.s3_endpoint }} \ --values ${{ inputs.values }} postgres . else - helm status postgres || \ helm upgrade --install --wait --values ${{ inputs.values }} postgres . fi diff --git a/charts/app/templates/backend/templates/deployment.yaml b/charts/app/templates/backend/templates/deployment.yaml index 6d8fd5ab0..3306f14ec 100644 --- a/charts/app/templates/backend/templates/deployment.yaml +++ b/charts/app/templates/backend/templates/deployment.yaml @@ -45,10 +45,10 @@ spec: resources: limits: cpu: 200m - memory: 100Mi + memory: 200Mi requests: cpu: 50m - memory: 25Mi + memory: 75Mi containers: - name: {{ include "backend.fullname" . }} {{- if .Values.backend.securityContext }} From 49f14979a7776b68f0fd90a8d2d2a81aed2d6e69 Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Sun, 27 Oct 2024 11:45:00 -0700 Subject: [PATCH 02/12] chore: postgres fine-tuning. Signed-off-by: OMPRAKASH MISHRA --- charts/crunchy/templates/PostgresCluster.yaml | 8 +++- charts/crunchy/templates/_helpers.tpl | 48 +++++++++++++++++++ charts/crunchy/values.yaml | 7 +-- 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/charts/crunchy/templates/PostgresCluster.yaml b/charts/crunchy/templates/PostgresCluster.yaml index 494d97038..fab8dc261 100644 --- a/charts/crunchy/templates/PostgresCluster.yaml +++ b/charts/crunchy/templates/PostgresCluster.yaml @@ -214,8 +214,11 @@ spec: postgresql: pg_hba: {{ toYaml .Values.crunchy.patroni.postgresql.pg_hba | nindent 10 }} parameters: - shared_buffers: {{ .Values.crunchy.patroni.postgresql.parameters.shared_buffers }} - wal_buffers: {{ .Values.crunchy.patroni.postgresql.parameters.wal_buffers }} + log_min_duration_statement: {{ .Values.crunchy.patroni.postgresql.parameters.log_min_duration_statement }} + max_connections: {{ .Values.crunchy.patroni.postgresql.parameters.max_connections }} + shared_buffers: {{ include "shared.buffers" . }} + wal_buffers: {{ include "wal.buffers" . }} + work_mem: {{ .Values.crunchy.patroni.postgresql.parameters.work_mem }} min_wal_size: {{ .Values.crunchy.patroni.postgresql.parameters.min_wal_size }} max_wal_size: {{ .Values.crunchy.patroni.postgresql.parameters.max_wal_size }} max_slot_wal_keep_size: {{ .Values.crunchy.patroni.postgresql.parameters.max_slot_wal_keep_size }} @@ -226,6 +229,7 @@ spec: global: client_tls_sslmode: disable pool_mode: session + max_db_connections: {{ include "pgbouncer.max.db.connections" . }} {{ if .Values.crunchy.proxy.pgBouncer.image }} image: {{ .Values.crunchy.proxy.pgBouncer.image }} {{ end }} diff --git a/charts/crunchy/templates/_helpers.tpl b/charts/crunchy/templates/_helpers.tpl index d6e89c6cc..0edabfc9a 100644 --- a/charts/crunchy/templates/_helpers.tpl +++ b/charts/crunchy/templates/_helpers.tpl @@ -68,3 +68,51 @@ repo2-s3-key={{ .Values.crunchy.pgBackRest.s3.accessKey }} repo2-s3-key-secret={{ .Values.crunchy.pgBackRest.s3.secretKey }} {{ end }} {{ end }} + +{{/* +Calculate the shared buffer to be 20% of allocated memory +https://vladmihalcea.com/postgresql-performance-tuning-settings/ +*/}} + +{{- define "shared.buffers"}} +{{- $memory := .Values.crunchy.instances.limits.memory -}} +{{- $unit := regexFind "([a-zA-Z]+)" $memory -}} +{{- $memoryValue := regexReplaceAll "([a-zA-Z]+)" $memory "" | int -}} +{{- $percentValue := (mulf $memoryValue 0.2) | int -}} +{{- printf "%d%s" $percentValue $unit -}} +{{- end }} + +{{/* +Calculate the effective cache size to be 50% of allocated memory + this value is closer to the official recommendation of setting it to a value between 50% and 75% of the available RAM. +*/}} + +{{- define "effective.cache.size"}} +{{- $memory := .Values.crunchy.instances.limits.memory -}} +{{- $unit := regexFind "([a-zA-Z]+)" $memory -}} +{{- $memoryValue := regexReplaceAll "([a-zA-Z]+)" $memory "" | int -}} +{{- $percentValue := (mulf $memoryValue 0.5) | int -}} +{{- printf "%d%s" $percentValue $unit -}} +{{- end }} + +{{/* +Another setting used for maintenance operations is wal_buffers, which allows storing in memory the WAL (Write-Ahead Log or Redo Log) segments before writing them to disk. By default, PostgreSQL uses a value that’s 1/32 of the shared_buffer setting. Therefore, my local PostgreSQL uses a value of 4 MB for the wal_buffers setting. +*/}} + +{{- define "wal.buffers"}} +{{- $sharedBuffers := include "shared.buffers" . -}} +{{- $unit := regexFind "([a-zA-Z]+)" $sharedBuffers -}} +{{- $memoryValue := regexReplaceAll "([a-zA-Z]+)" $sharedBuffers "" | int -}} +{{- $percentValue := (mulf $memoryValue 0.03) | int -}} +{{- printf "%d%s" $percentValue $unit -}} +{{- end }} + +{{/* +Calculate pg bouncer max connections to DB, 20% of overall. +*/}} + +{{- define "pgbouncer.max.db.connections"}} +{{- $connections := .Values.crunchy.patroni.postgresql.parameters.max_connections -}} +{{- $pgBouncerMaxCon := (mulf $connections 0.1) | int -}} +{{- printf "%d" $pgBouncerMaxCon -}} +{{- end }} diff --git a/charts/crunchy/values.yaml b/charts/crunchy/values.yaml index c2c6c50dd..03725cbd6 100644 --- a/charts/crunchy/values.yaml +++ b/charts/crunchy/values.yaml @@ -108,15 +108,16 @@ crunchy: # enable it for TEST and PROD, for PR based pipelines simply use single patroni: postgresql: - pg_hba: + pg_hba: - "host all all 0.0.0.0/0 md5" - "host all all ::1/128 md5" parameters: - shared_buffers: 16MB # default is 128MB; a good tuned default for shared_buffers is 25% of the memory allocated to the pod - wal_buffers: "64kB" # this can be set to -1 to automatically set as 1/32 of shared_buffers or 64kB, whichever is larger min_wal_size: 32MB max_wal_size: 64MB # default is 1GB max_slot_wal_keep_size: 96MB # default is -1, allowing unlimited wal growth when replicas fall behind + max_connections: 20 # based on small cluster. + work_mem: 2MB # a work_mem value of 2 MB, so for 20 database connections, PostgreSQL could use 40 MB of RAM for query operations. + log_min_duration_statement: 1000ms # log queries taking more than 1 second to respond. proxy: enabled: true From 1d937422a98d645affac5a0c94f669db8dc852a2 Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Sun, 27 Oct 2024 11:48:11 -0700 Subject: [PATCH 03/12] make max_db_connections int Signed-off-by: OMPRAKASH MISHRA --- charts/crunchy/templates/PostgresCluster.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/crunchy/templates/PostgresCluster.yaml b/charts/crunchy/templates/PostgresCluster.yaml index fab8dc261..7f0423556 100644 --- a/charts/crunchy/templates/PostgresCluster.yaml +++ b/charts/crunchy/templates/PostgresCluster.yaml @@ -229,7 +229,7 @@ spec: global: client_tls_sslmode: disable pool_mode: session - max_db_connections: {{ include "pgbouncer.max.db.connections" . }} + max_db_connections: {{ include "pgbouncer.max.db.connections" . | int }} {{ if .Values.crunchy.proxy.pgBouncer.image }} image: {{ .Values.crunchy.proxy.pgBouncer.image }} {{ end }} From fcbdbd896ef3f1355d764b3db0024a730d3f968e Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Sun, 27 Oct 2024 11:49:37 -0700 Subject: [PATCH 04/12] make max_db_connections string Signed-off-by: OMPRAKASH MISHRA --- charts/crunchy/templates/PostgresCluster.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/crunchy/templates/PostgresCluster.yaml b/charts/crunchy/templates/PostgresCluster.yaml index 7f0423556..4e788476e 100644 --- a/charts/crunchy/templates/PostgresCluster.yaml +++ b/charts/crunchy/templates/PostgresCluster.yaml @@ -229,7 +229,7 @@ spec: global: client_tls_sslmode: disable pool_mode: session - max_db_connections: {{ include "pgbouncer.max.db.connections" . | int }} + max_db_connections: {{ include "pgbouncer.max.db.connections" . | quote }} {{ if .Values.crunchy.proxy.pgBouncer.image }} image: {{ .Values.crunchy.proxy.pgBouncer.image }} {{ end }} From abf791de08499c33a437f0d5b69cf8c7ea23b56d Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Sun, 27 Oct 2024 12:22:43 -0700 Subject: [PATCH 05/12] chore: rename DB deployer and add concurrency Signed-off-by: OMPRAKASH MISHRA --- .github/workflows/.dbdeployer.yml | 2 +- charts/crunchy/templates/PostgresCluster.yaml | 1 + charts/crunchy/values.yaml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/.dbdeployer.yml b/.github/workflows/.dbdeployer.yml index 3daa2ab86..dfb07054a 100644 --- a/.github/workflows/.dbdeployer.yml +++ b/.github/workflows/.dbdeployer.yml @@ -48,7 +48,7 @@ on: jobs: deploy_db: runs-on: ubuntu-24.04 - name: Deploy Crunchy DB If not Deployed + name: Deploy Or Upgrade Crunchy DB environment: ${{ inputs.environment }} steps: - uses: actions/checkout@v4 diff --git a/charts/crunchy/templates/PostgresCluster.yaml b/charts/crunchy/templates/PostgresCluster.yaml index 4e788476e..ddb9ee182 100644 --- a/charts/crunchy/templates/PostgresCluster.yaml +++ b/charts/crunchy/templates/PostgresCluster.yaml @@ -222,6 +222,7 @@ spec: min_wal_size: {{ .Values.crunchy.patroni.postgresql.parameters.min_wal_size }} max_wal_size: {{ .Values.crunchy.patroni.postgresql.parameters.max_wal_size }} max_slot_wal_keep_size: {{ .Values.crunchy.patroni.postgresql.parameters.max_slot_wal_keep_size }} + effective_io_concurrency: {{ .Values.crunchy.patroni.postgresql.parameters.effective_io_concurrency }} {{- if and .Values.crunchy.proxy .Values.crunchy.proxy.enabled }} proxy: pgBouncer: diff --git a/charts/crunchy/values.yaml b/charts/crunchy/values.yaml index 03725cbd6..63508e786 100644 --- a/charts/crunchy/values.yaml +++ b/charts/crunchy/values.yaml @@ -118,6 +118,7 @@ crunchy: # enable it for TEST and PROD, for PR based pipelines simply use single max_connections: 20 # based on small cluster. work_mem: 2MB # a work_mem value of 2 MB, so for 20 database connections, PostgreSQL could use 40 MB of RAM for query operations. log_min_duration_statement: 1000ms # log queries taking more than 1 second to respond. + effective_io_concurrency: 20 #If the underlying disk can handle multiple simultaneous requests, then you should increase the effective_io_concurrency value and test what value provides the best application performance. All BCGov clusters have SSD. proxy: enabled: true From 8dd5a5e32191110f50e094b7826ba65ff749afdf Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Sun, 27 Oct 2024 16:42:02 -0700 Subject: [PATCH 06/12] fix: swagger docs path Signed-off-by: OMPRAKASH MISHRA --- backend/src/app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/app.ts b/backend/src/app.ts index 62d31899b..7a109bbd1 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -33,6 +33,6 @@ export async function bootstrap() { .build(); const document = SwaggerModule.createDocument(app, config); - SwaggerModule.setup("docs", app, document); + SwaggerModule.setup("/api/docs", app, document); return app; } From b62b05e6b2b008116257f2a4b1aa57aaab6d58d0 Mon Sep 17 00:00:00 2001 From: Om Mishra <32200996+mishraomp@users.noreply.github.com> Date: Sun, 27 Oct 2024 18:48:06 -0700 Subject: [PATCH 07/12] trying with MB and GB using ternary. --- charts/crunchy/templates/_helpers.tpl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/charts/crunchy/templates/_helpers.tpl b/charts/crunchy/templates/_helpers.tpl index 0edabfc9a..cc94e6dd0 100644 --- a/charts/crunchy/templates/_helpers.tpl +++ b/charts/crunchy/templates/_helpers.tpl @@ -79,7 +79,8 @@ https://vladmihalcea.com/postgresql-performance-tuning-settings/ {{- $unit := regexFind "([a-zA-Z]+)" $memory -}} {{- $memoryValue := regexReplaceAll "([a-zA-Z]+)" $memory "" | int -}} {{- $percentValue := (mulf $memoryValue 0.2) | int -}} -{{- printf "%d%s" $percentValue $unit -}} +{{- $newUnit := ternary (eq $unit "Gi") "GB" "MB" -}} +{{- printf "%d%s" $percentValue $newUnit -}} {{- end }} {{/* @@ -104,7 +105,8 @@ Another setting used for maintenance operations is wal_buffers, which allows sto {{- $unit := regexFind "([a-zA-Z]+)" $sharedBuffers -}} {{- $memoryValue := regexReplaceAll "([a-zA-Z]+)" $sharedBuffers "" | int -}} {{- $percentValue := (mulf $memoryValue 0.03) | int -}} -{{- printf "%d%s" $percentValue $unit -}} +{{- $newUnit := ternary (eq $unit "Gi") "GB" "MB" -}} +{{- printf "%d%s" $percentValue $newUnit -}} {{- end }} {{/* From 11f44de966568bb500d410d8a73256c1d3277e3a Mon Sep 17 00:00:00 2001 From: Om Mishra <32200996+mishraomp@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:39:20 -0700 Subject: [PATCH 08/12] trying different.. --- charts/crunchy/templates/_helpers.tpl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/charts/crunchy/templates/_helpers.tpl b/charts/crunchy/templates/_helpers.tpl index cc94e6dd0..4d8577a04 100644 --- a/charts/crunchy/templates/_helpers.tpl +++ b/charts/crunchy/templates/_helpers.tpl @@ -79,7 +79,7 @@ https://vladmihalcea.com/postgresql-performance-tuning-settings/ {{- $unit := regexFind "([a-zA-Z]+)" $memory -}} {{- $memoryValue := regexReplaceAll "([a-zA-Z]+)" $memory "" | int -}} {{- $percentValue := (mulf $memoryValue 0.2) | int -}} -{{- $newUnit := ternary (eq $unit "Gi") "GB" "MB" -}} +{{- $newUnit := $unit | replace "i" "B" -}} {{- printf "%d%s" $percentValue $newUnit -}} {{- end }} @@ -105,8 +105,7 @@ Another setting used for maintenance operations is wal_buffers, which allows sto {{- $unit := regexFind "([a-zA-Z]+)" $sharedBuffers -}} {{- $memoryValue := regexReplaceAll "([a-zA-Z]+)" $sharedBuffers "" | int -}} {{- $percentValue := (mulf $memoryValue 0.03) | int -}} -{{- $newUnit := ternary (eq $unit "Gi") "GB" "MB" -}} -{{- printf "%d%s" $percentValue $newUnit -}} +{{- printf "%d%s" $percentValue $unit -}} {{- end }} {{/* From 1202f52ed77bc5d423e4278a643fd867bcec0935 Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Mon, 28 Oct 2024 08:01:54 -0700 Subject: [PATCH 09/12] chore: update wal storage Signed-off-by: OMPRAKASH MISHRA --- charts/crunchy/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/crunchy/values.yaml b/charts/crunchy/values.yaml index 63508e786..876b87634 100644 --- a/charts/crunchy/values.yaml +++ b/charts/crunchy/values.yaml @@ -34,7 +34,7 @@ crunchy: # enable it for TEST and PROD, for PR based pipelines simply use single dataVolumeClaimSpec: storage: 200Mi storageClassName: netapp-block-standard - walStorage: 225Mi + walStorage: 255Mi requests: cpu: 50m From de20907b9b69bef47fcc9b521789d4e3473d71af Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Mon, 28 Oct 2024 10:30:37 -0700 Subject: [PATCH 10/12] few more config changes Signed-off-by: OMPRAKASH MISHRA --- charts/crunchy/templates/PostgresCluster.yaml | 5 ++-- charts/crunchy/templates/_helpers.tpl | 24 ------------------- charts/crunchy/values.yaml | 7 +++--- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/charts/crunchy/templates/PostgresCluster.yaml b/charts/crunchy/templates/PostgresCluster.yaml index ddb9ee182..2fd041495 100644 --- a/charts/crunchy/templates/PostgresCluster.yaml +++ b/charts/crunchy/templates/PostgresCluster.yaml @@ -215,9 +215,8 @@ spec: pg_hba: {{ toYaml .Values.crunchy.patroni.postgresql.pg_hba | nindent 10 }} parameters: log_min_duration_statement: {{ .Values.crunchy.patroni.postgresql.parameters.log_min_duration_statement }} - max_connections: {{ .Values.crunchy.patroni.postgresql.parameters.max_connections }} - shared_buffers: {{ include "shared.buffers" . }} - wal_buffers: {{ include "wal.buffers" . }} + shared_buffers: {{ .Values.crunchy.patroni.postgresql.parameters.shared_buffers }} + wal_buffers: {{ .Values.crunchy.patroni.postgresql.parameters.wal_buffers }} work_mem: {{ .Values.crunchy.patroni.postgresql.parameters.work_mem }} min_wal_size: {{ .Values.crunchy.patroni.postgresql.parameters.min_wal_size }} max_wal_size: {{ .Values.crunchy.patroni.postgresql.parameters.max_wal_size }} diff --git a/charts/crunchy/templates/_helpers.tpl b/charts/crunchy/templates/_helpers.tpl index 4d8577a04..355c01dfb 100644 --- a/charts/crunchy/templates/_helpers.tpl +++ b/charts/crunchy/templates/_helpers.tpl @@ -69,19 +69,6 @@ repo2-s3-key-secret={{ .Values.crunchy.pgBackRest.s3.secretKey }} {{ end }} {{ end }} -{{/* -Calculate the shared buffer to be 20% of allocated memory -https://vladmihalcea.com/postgresql-performance-tuning-settings/ -*/}} - -{{- define "shared.buffers"}} -{{- $memory := .Values.crunchy.instances.limits.memory -}} -{{- $unit := regexFind "([a-zA-Z]+)" $memory -}} -{{- $memoryValue := regexReplaceAll "([a-zA-Z]+)" $memory "" | int -}} -{{- $percentValue := (mulf $memoryValue 0.2) | int -}} -{{- $newUnit := $unit | replace "i" "B" -}} -{{- printf "%d%s" $percentValue $newUnit -}} -{{- end }} {{/* Calculate the effective cache size to be 50% of allocated memory @@ -96,17 +83,6 @@ Calculate the effective cache size to be 50% of allocated memory {{- printf "%d%s" $percentValue $unit -}} {{- end }} -{{/* -Another setting used for maintenance operations is wal_buffers, which allows storing in memory the WAL (Write-Ahead Log or Redo Log) segments before writing them to disk. By default, PostgreSQL uses a value that’s 1/32 of the shared_buffer setting. Therefore, my local PostgreSQL uses a value of 4 MB for the wal_buffers setting. -*/}} - -{{- define "wal.buffers"}} -{{- $sharedBuffers := include "shared.buffers" . -}} -{{- $unit := regexFind "([a-zA-Z]+)" $sharedBuffers -}} -{{- $memoryValue := regexReplaceAll "([a-zA-Z]+)" $sharedBuffers "" | int -}} -{{- $percentValue := (mulf $memoryValue 0.03) | int -}} -{{- printf "%d%s" $percentValue $unit -}} -{{- end }} {{/* Calculate pg bouncer max connections to DB, 20% of overall. diff --git a/charts/crunchy/values.yaml b/charts/crunchy/values.yaml index 876b87634..92f6fc457 100644 --- a/charts/crunchy/values.yaml +++ b/charts/crunchy/values.yaml @@ -112,11 +112,12 @@ crunchy: # enable it for TEST and PROD, for PR based pipelines simply use single - "host all all 0.0.0.0/0 md5" - "host all all ::1/128 md5" parameters: + shared_buffers: 16MB # default is 128MB; a good tuned default for shared_buffers is 25% of the memory allocated to the pod + wal_buffers: "64kB" # this can be set to -1 to automatically set as 1/32 of shared_buffers or 64kB, whichever is larger min_wal_size: 32MB max_wal_size: 64MB # default is 1GB - max_slot_wal_keep_size: 96MB # default is -1, allowing unlimited wal growth when replicas fall behind - max_connections: 20 # based on small cluster. - work_mem: 2MB # a work_mem value of 2 MB, so for 20 database connections, PostgreSQL could use 40 MB of RAM for query operations. + max_slot_wal_keep_size: 128MB # default is -1, allowing unlimited wal growth when replicas fall behind + work_mem: 2MB # a work_mem value of 2 MB log_min_duration_statement: 1000ms # log queries taking more than 1 second to respond. effective_io_concurrency: 20 #If the underlying disk can handle multiple simultaneous requests, then you should increase the effective_io_concurrency value and test what value provides the best application performance. All BCGov clusters have SSD. From dd1259a52e111505310286f74745adb4646fbc67 Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Mon, 28 Oct 2024 10:43:46 -0700 Subject: [PATCH 11/12] few more updates, to align with defaults Signed-off-by: OMPRAKASH MISHRA --- charts/crunchy/templates/PostgresCluster.yaml | 2 +- charts/crunchy/templates/_helpers.tpl | 9 --------- charts/crunchy/values.yaml | 1 + 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/charts/crunchy/templates/PostgresCluster.yaml b/charts/crunchy/templates/PostgresCluster.yaml index 2fd041495..2fc074f27 100644 --- a/charts/crunchy/templates/PostgresCluster.yaml +++ b/charts/crunchy/templates/PostgresCluster.yaml @@ -229,7 +229,7 @@ spec: global: client_tls_sslmode: disable pool_mode: session - max_db_connections: {{ include "pgbouncer.max.db.connections" . | quote }} + max_db_connections: {{ .Values.crunchy.proxy.pgBouncer.maxConnections | quote }} {{ if .Values.crunchy.proxy.pgBouncer.image }} image: {{ .Values.crunchy.proxy.pgBouncer.image }} {{ end }} diff --git a/charts/crunchy/templates/_helpers.tpl b/charts/crunchy/templates/_helpers.tpl index 355c01dfb..6e3985bc2 100644 --- a/charts/crunchy/templates/_helpers.tpl +++ b/charts/crunchy/templates/_helpers.tpl @@ -84,12 +84,3 @@ Calculate the effective cache size to be 50% of allocated memory {{- end }} -{{/* -Calculate pg bouncer max connections to DB, 20% of overall. -*/}} - -{{- define "pgbouncer.max.db.connections"}} -{{- $connections := .Values.crunchy.patroni.postgresql.parameters.max_connections -}} -{{- $pgBouncerMaxCon := (mulf $connections 0.1) | int -}} -{{- printf "%d" $pgBouncerMaxCon -}} -{{- end }} diff --git a/charts/crunchy/values.yaml b/charts/crunchy/values.yaml index 92f6fc457..af200522c 100644 --- a/charts/crunchy/values.yaml +++ b/charts/crunchy/values.yaml @@ -132,6 +132,7 @@ crunchy: # enable it for TEST and PROD, for PR based pipelines simply use single limits: cpu: 20m memory: 64Mi + maxConnections: 10 # make sure less than postgres max connections # Postgres Cluster resource values: pgmonitor: From cfd6b9244b71d39e8cbfa5f894fdfd421cb7e371 Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Mon, 28 Oct 2024 10:45:02 -0700 Subject: [PATCH 12/12] remove the unused var Signed-off-by: OMPRAKASH MISHRA --- charts/crunchy/templates/_helpers.tpl | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/charts/crunchy/templates/_helpers.tpl b/charts/crunchy/templates/_helpers.tpl index 6e3985bc2..d6e89c6cc 100644 --- a/charts/crunchy/templates/_helpers.tpl +++ b/charts/crunchy/templates/_helpers.tpl @@ -68,19 +68,3 @@ repo2-s3-key={{ .Values.crunchy.pgBackRest.s3.accessKey }} repo2-s3-key-secret={{ .Values.crunchy.pgBackRest.s3.secretKey }} {{ end }} {{ end }} - - -{{/* -Calculate the effective cache size to be 50% of allocated memory - this value is closer to the official recommendation of setting it to a value between 50% and 75% of the available RAM. -*/}} - -{{- define "effective.cache.size"}} -{{- $memory := .Values.crunchy.instances.limits.memory -}} -{{- $unit := regexFind "([a-zA-Z]+)" $memory -}} -{{- $memoryValue := regexReplaceAll "([a-zA-Z]+)" $memory "" | int -}} -{{- $percentValue := (mulf $memoryValue 0.5) | int -}} -{{- printf "%d%s" $percentValue $unit -}} -{{- end }} - -