Skip to content

Commit 2d98e02

Browse files
committed
Resource fixes
1 parent 4dd097a commit 2d98e02

File tree

15 files changed

+505
-8
lines changed

15 files changed

+505
-8
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Minimal resource configuration for crAPI
2+
# Runs on ~2 CPUs minimum, scales up when more resources available
3+
# Usage: docker-compose -f docker-compose.yml -f docker-compose.minimal.yml up
4+
5+
services:
6+
crapi-identity:
7+
deploy:
8+
resources:
9+
limits:
10+
cpus: '1.0'
11+
memory: 512M
12+
reservations:
13+
cpus: '0.25'
14+
memory: 128M
15+
16+
crapi-community:
17+
deploy:
18+
resources:
19+
limits:
20+
cpus: '0.5'
21+
memory: 256M
22+
reservations:
23+
cpus: '0.15'
24+
memory: 64M
25+
26+
crapi-workshop:
27+
deploy:
28+
resources:
29+
limits:
30+
cpus: '1.5'
31+
memory: 768M
32+
reservations:
33+
cpus: '0.4'
34+
memory: 192M
35+
36+
crapi-chatbot:
37+
deploy:
38+
resources:
39+
limits:
40+
cpus: '0.5'
41+
memory: 256M
42+
reservations:
43+
cpus: '0.1'
44+
memory: 64M
45+
46+
crapi-web:
47+
deploy:
48+
resources:
49+
limits:
50+
cpus: '0.5'
51+
memory: 192M
52+
reservations:
53+
cpus: '0.1'
54+
memory: 64M
55+
56+
postgresdb:
57+
deploy:
58+
resources:
59+
limits:
60+
cpus: '1.0'
61+
memory: 512M
62+
reservations:
63+
cpus: '0.3'
64+
memory: 128M
65+
66+
mongodb:
67+
deploy:
68+
resources:
69+
limits:
70+
cpus: '0.5'
71+
memory: 256M
72+
reservations:
73+
cpus: '0.2'
74+
memory: 64M
75+
76+
chromadb:
77+
deploy:
78+
resources:
79+
limits:
80+
cpus: '0.5'
81+
memory: 256M
82+
reservations:
83+
cpus: '0.1'
84+
memory: 64M
85+
86+
mailhog:
87+
deploy:
88+
resources:
89+
limits:
90+
cpus: '0.3'
91+
memory: 128M
92+
reservations:
93+
cpus: '0.05'
94+
memory: 32M
95+
96+
api.mypremiumdealership.com:
97+
deploy:
98+
resources:
99+
limits:
100+
cpus: '0.2'
101+
memory: 64M
102+
reservations:
103+
cpus: '0.05'
104+
memory: 16M
105+
106+
# Total reservations (minimum): ~1.65 CPUs, ~800MB RAM
107+
# Total limits (maximum when available): ~6.0 CPUs, ~3.2GB RAM

deploy/docker/docker-compose.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ services:
131131
- TLS_CERTIFICATE=certs/server.crt
132132
- TLS_KEY=certs/server.key
133133
- FILES_LIMIT=1000
134+
# Gunicorn configuration for better performance under load
135+
- GUNICORN_WORKERS=${GUNICORN_WORKERS:-4}
136+
- GUNICORN_TIMEOUT=${GUNICORN_TIMEOUT:-120}
137+
- GUNICORN_MAX_REQUESTS=${GUNICORN_MAX_REQUESTS:-1000}
138+
- GUNICORN_MAX_REQUESTS_JITTER=${GUNICORN_MAX_REQUESTS_JITTER:-50}
139+
# Database connection pooling (10 minutes)
140+
- DB_CONN_MAX_AGE=${DB_CONN_MAX_AGE:-600}
134141
depends_on:
135142
postgresdb:
136143
condition: service_healthy
@@ -148,8 +155,8 @@ services:
148155
deploy:
149156
resources:
150157
limits:
151-
cpus: '0.3'
152-
memory: 128M
158+
cpus: '1.0'
159+
memory: 512M
153160

154161
crapi-chatbot:
155162
container_name: crapi-chatbot
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{{- if .Values.community.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ .Values.community.name }}-hpa
6+
labels:
7+
release: {{ .Release.Name }}
8+
app: {{ .Values.community.name }}
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: {{ .Values.community.name }}
14+
minReplicas: {{ .Values.community.autoscaling.minReplicas | default 1 }}
15+
maxReplicas: {{ .Values.community.autoscaling.maxReplicas | default 3 }}
16+
metrics:
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.community.autoscaling.targetCPUUtilizationPercentage | default 70 }}
23+
{{- if .Values.community.autoscaling.targetMemoryUtilizationPercentage }}
24+
- type: Resource
25+
resource:
26+
name: memory
27+
target:
28+
type: Utilization
29+
averageUtilization: {{ .Values.community.autoscaling.targetMemoryUtilizationPercentage }}
30+
{{- end }}
31+
{{- end }}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{{- if .Values.identity.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ .Values.identity.name }}-hpa
6+
labels:
7+
release: {{ .Release.Name }}
8+
app: {{ .Values.identity.name }}
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: {{ .Values.identity.name }}
14+
minReplicas: {{ .Values.identity.autoscaling.minReplicas | default 1 }}
15+
maxReplicas: {{ .Values.identity.autoscaling.maxReplicas | default 3 }}
16+
metrics:
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.identity.autoscaling.targetCPUUtilizationPercentage | default 70 }}
23+
{{- if .Values.identity.autoscaling.targetMemoryUtilizationPercentage }}
24+
- type: Resource
25+
resource:
26+
name: memory
27+
target:
28+
type: Utilization
29+
averageUtilization: {{ .Values.identity.autoscaling.targetMemoryUtilizationPercentage }}
30+
{{- end }}
31+
{{- end }}

deploy/helm/templates/workshop/config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ data:
2323
API_GATEWAY_URL: {{ if .Values.apiGatewayServiceInstall }}"https://{{ .Values.apiGatewayService.service.name }}"{{ else }}{{ .Values.apiGatewayServiceUrl }}{{ end }}
2424
TLS_ENABLED: {{ .Values.tlsEnabled | quote }}
2525
FILES_LIMIT: {{ .Values.workshop.config.filesLimit | quote }}
26+
# Gunicorn configuration for better performance under load
27+
GUNICORN_WORKERS: {{ .Values.workshop.config.gunicornWorkers | default "4" | quote }}
28+
GUNICORN_TIMEOUT: {{ .Values.workshop.config.gunicornTimeout | default "120" | quote }}
29+
GUNICORN_MAX_REQUESTS: {{ .Values.workshop.config.gunicornMaxRequests | default "1000" | quote }}
30+
GUNICORN_MAX_REQUESTS_JITTER: {{ .Values.workshop.config.gunicornMaxRequestsJitter | default "50" | quote }}
31+
# Database connection pooling
32+
DB_CONN_MAX_AGE: {{ .Values.workshop.config.dbConnMaxAge | default "600" | quote }}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{- if .Values.workshop.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ .Values.workshop.name }}-hpa
6+
labels:
7+
release: {{ .Release.Name }}
8+
app: {{ .Values.workshop.name }}
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: {{ .Values.workshop.name }}
14+
minReplicas: {{ .Values.workshop.autoscaling.minReplicas | default 1 }}
15+
maxReplicas: {{ .Values.workshop.autoscaling.maxReplicas | default 5 }}
16+
metrics:
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.workshop.autoscaling.targetCPUUtilizationPercentage | default 70 }}
23+
{{- if .Values.workshop.autoscaling.targetMemoryUtilizationPercentage }}
24+
- type: Resource
25+
resource:
26+
name: memory
27+
target:
28+
type: Utilization
29+
averageUtilization: {{ .Values.workshop.autoscaling.targetMemoryUtilizationPercentage }}
30+
{{- end }}
31+
{{- if .Values.workshop.autoscaling.behavior }}
32+
behavior:
33+
{{- toYaml .Values.workshop.autoscaling.behavior | nindent 4 }}
34+
{{- end }}
35+
{{- end }}

deploy/helm/values-minimal.yaml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Minimal resource configuration for Helm deployment
2+
# Minimum ~2 CPUs, scales up when more resources available
3+
# Usage: helm install crapi ./deploy/helm -f values-minimal.yaml
4+
5+
# Global settings
6+
imagePullPolicy: IfNotPresent
7+
8+
identity:
9+
replicaCount: 1
10+
resources:
11+
requests:
12+
cpu: "250m"
13+
memory: "128Mi"
14+
limits:
15+
cpu: "1000m"
16+
memory: "512Mi"
17+
autoscaling:
18+
enabled: true
19+
minReplicas: 1
20+
maxReplicas: 3
21+
targetCPUUtilizationPercentage: 70
22+
23+
community:
24+
replicaCount: 1
25+
resources:
26+
requests:
27+
cpu: "150m"
28+
memory: "64Mi"
29+
limits:
30+
cpu: "500m"
31+
memory: "256Mi"
32+
autoscaling:
33+
enabled: true
34+
minReplicas: 1
35+
maxReplicas: 3
36+
targetCPUUtilizationPercentage: 70
37+
38+
workshop:
39+
replicaCount: 1
40+
resources:
41+
requests:
42+
cpu: "400m"
43+
memory: "192Mi"
44+
limits:
45+
cpu: "1500m"
46+
memory: "768Mi"
47+
autoscaling:
48+
enabled: true
49+
minReplicas: 1
50+
maxReplicas: 5
51+
targetCPUUtilizationPercentage: 70
52+
config:
53+
gunicornWorkers: 2 # Start with 2, will scale horizontally via HPA
54+
55+
chatbot:
56+
replicaCount: 1
57+
resources:
58+
requests:
59+
cpu: "100m"
60+
memory: "64Mi"
61+
limits:
62+
cpu: "500m"
63+
memory: "256Mi"
64+
65+
web:
66+
replicaCount: 1
67+
resources:
68+
requests:
69+
cpu: "100m"
70+
memory: "64Mi"
71+
limits:
72+
cpu: "500m"
73+
memory: "192Mi"
74+
75+
postgresdb:
76+
resources:
77+
requests:
78+
cpu: "300m"
79+
memory: "128Mi"
80+
limits:
81+
cpu: "1000m"
82+
memory: "512Mi"
83+
84+
mongodb:
85+
resources:
86+
requests:
87+
cpu: "200m"
88+
memory: "64Mi"
89+
limits:
90+
cpu: "500m"
91+
memory: "256Mi"
92+
93+
chromadb:
94+
resources:
95+
requests:
96+
cpu: "100m"
97+
memory: "64Mi"
98+
limits:
99+
cpu: "500m"
100+
memory: "256Mi"
101+
102+
mailhog:
103+
resources:
104+
requests:
105+
cpu: "50m"
106+
memory: "32Mi"
107+
limits:
108+
cpu: "300m"
109+
memory: "128Mi"
110+
111+
apiGatewayService:
112+
resources:
113+
requests:
114+
cpu: "50m"
115+
memory: "16Mi"
116+
limits:
117+
cpu: "200m"
118+
memory: "64Mi"
119+
120+
# Total minimum requests: ~1.7 CPUs, ~800MB RAM
121+
# Total maximum limits: ~6.5 CPUs, ~3.2GB RAM

0 commit comments

Comments
 (0)