Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions k8s-manifests/storedog-app/configmaps/postgres-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,43 @@ metadata:
name: postgres-config
data:
postgresql.conf: |
# Connection Settings
listen_addresses = '*'
max_connections = 200
shared_buffers = 128MB
dynamic_shared_memory_type = posix
max_connections = 300

# Memory Configuration
shared_buffers = 256MB # Increased from default 128MB
effective_cache_size = 768MB # 3/4 of available memory
work_mem = 8MB # Per-operation memory
maintenance_work_mem = 64MB # For maintenance operations

# Query Planner
random_page_cost = 1.5 # SSD optimization
effective_io_concurrency = 200 # SSD optimization
seq_page_cost = 1.0

# WAL Configuration
wal_buffers = 16MB
checkpoint_completion_target = 0.9
wal_writer_delay = 200ms
commit_delay = 1000 # Microseconds
commit_siblings = 5

# Connection Pooling Support
tcp_keepalives_idle = 300
tcp_keepalives_interval = 30
tcp_keepalives_count = 3

# Query Optimization
log_min_duration_statement = 1000 # Log slow queries (>1s)
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on

# Performance Monitoring
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.track = all
track_activity_query_size = 2048
track_counts = on
track_functions = all
94 changes: 94 additions & 0 deletions k8s-manifests/storedog-app/configmaps/redis-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-config
data:
redis.conf: |
# Network Configuration
bind 0.0.0.0
port 6379
tcp-backlog 1024
timeout 300
tcp-keepalive 300

# Database Configuration - Support multiple databases for different cache types
databases 16

# Memory Management - Optimized for caching workloads
maxmemory 400mb
maxmemory-policy allkeys-lru
maxmemory-samples 10

# Connection Settings - Increased for heavy caching
maxclients 2000

# Persistence Configuration - Balanced for cache data
save 900 1
save 300 10
save 60 10000

# AOF Configuration - Optimized for cache performance
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 32mb
aof-rewrite-incremental-fsync yes

# Performance Tuning for Caching Workloads
# Optimized for storing larger cache objects
hash-max-ziplist-entries 1024
hash-max-ziplist-value 1024
list-max-ziplist-size -1
list-compress-depth 1
set-max-intset-entries 1024
zset-max-ziplist-entries 256
zset-max-ziplist-value 128

# HyperLogLog sparse representation
hll-sparse-max-bytes 3000

# Stream configuration for real-time features
stream-node-max-bytes 4096
stream-node-max-entries 100

# Lazy Freeing - Important for cache eviction performance
lazyfree-lazy-eviction yes
lazyfree-lazy-expire yes
lazyfree-lazy-server-del yes
replica-lazy-flush yes

# Client Output Buffer Limits - Increased for cache responses
client-output-buffer-limit normal 32mb 16mb 60
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

# Cache-Specific Optimizations
# Faster key expiration for cache cleanup
hz 50

# Memory usage optimization
activerehashing yes

# Replication and clustering (for future scaling)
replica-serve-stale-data yes
replica-read-only yes

# Security - Basic protection
protected-mode no

# Threading - Utilize available CPU
io-threads 2
io-threads-do-reads yes

# Logging - Detailed for cache monitoring
loglevel notice
logfile ""

# Slow log for cache performance monitoring
slowlog-log-slower-than 10000
slowlog-max-len 1000

# Latency monitoring
latency-monitor-threshold 100
61 changes: 51 additions & 10 deletions k8s-manifests/storedog-app/configmaps/shared-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,59 @@ kind: ConfigMap
metadata:
name: storedog-config
data:
# Database Configuration
POSTGRES_USER: postgres
DB_HOST: postgres
DB_PORT: "5432"
REDIS_URL: redis://redis:6379/0
RAILS_ENV: production
DB_POOL: "25"
MAX_THREADS: "5"
NEXT_PUBLIC_ADS_ROUTE: /services/ads
NEXT_PUBLIC_DISCOUNTS_ROUTE: /services/discounts
NEXT_PUBLIC_DBM_ROUTE: /services/dbm
NEXT_PUBLIC_FRONTEND_API_ROUTE: http://service-proxy:80
NEXT_PUBLIC_SPREE_API_HOST: http://service-proxy/services/backend
NEXT_PUBLIC_SPREE_CLIENT_HOST: /services/backend
NEXT_PUBLIC_SPREE_IMAGE_HOST: /services/backend
NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN: service-proxy

# Redis Configuration
REDIS_URL: redis://redis:6379/0

# Rails Environment
RAILS_ENV: production # production mode with debug logging enabled

# ======== REDIS CACHING CONFIGURATION ========

# 1. Rails Cache Store - Use Redis for all Rails caching
RAILS_CACHE_STORE: "redis_cache_store"
CACHE_REDIS_URL: "redis://redis:6379/1" # Use database 1 for caching

# 2. Session Store - Store user sessions in Redis
SESSION_STORE: "redis_store"
SESSION_REDIS_URL: "redis://redis:6379/2" # Use database 2 for sessions
SESSION_EXPIRE_AFTER: "7200" # 2 hours

# 3. Fragment Caching - Enable aggressive fragment caching
RAILS_CACHE_FRAGMENT: "true"
CACHE_DEFAULT_EXPIRES_IN: "3600" # 1 hour default
CACHE_PRODUCT_EXPIRES_IN: "1800" # 30 minutes for products
CACHE_CATEGORY_EXPIRES_IN: "7200" # 2 hours for categories

# 4. Query Result Caching
RAILS_CACHE_QUERIES: "true"
CACHE_QUERY_EXPIRES_IN: "900" # 15 minutes for query results

# 5. Action Caching
RAILS_CACHE_ACTIONS: "true"
CACHE_ACTION_EXPIRES_IN: "1800" # 30 minutes for action caching

# 6. Page Caching (for static-like content)
RAILS_CACHE_PAGES: "true"
CACHE_PAGE_EXPIRES_IN: "3600" # 1 hour for page caching

# 7. HTTP Caching Headers
RAILS_STATIC_CACHE_CONTROL: "public, max-age=31536000" # 1 year for assets
RAILS_CACHE_CONTROL: "public, max-age=3600" # 1 hour for dynamic content

# 8. Redis Cache Optimization
CACHE_REDIS_POOL_SIZE: "25"
CACHE_REDIS_POOL_TIMEOUT: "5"
CACHE_REDIS_RECONNECT_ATTEMPTS: "3"
CACHE_REDIS_RECONNECT_DELAY: "1.5"

# 9. Performance Caching Settings
RAILS_CACHE_VERSIONING: "true" # Enable cache versioning
RAILS_CACHE_COMPRESSION: "true" # Compress cached data
CACHE_COMPRESS_THRESHOLD: "1024" # Compress if > 1KB
6 changes: 3 additions & 3 deletions k8s-manifests/storedog-app/deployments/ads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ spec:
value: "true"
resources:
requests:
memory: "256Mi"
cpu: "200m"
cpu: "100m"
memory: "384Mi"
limits:
cpu: "300m"
memory: "512Mi"
cpu: "400m"
volumeMounts:
- name: apmsocketpath
mountPath: /var/run/datadog
8 changes: 4 additions & 4 deletions k8s-manifests/storedog-app/deployments/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ spec:
value: "true"
resources:
requests:
memory: "512Mi"
cpu: "250m"
cpu: "100m"
memory: "384Mi"
limits:
memory: "1Gi"
cpu: "500m"
cpu: "400m"
memory: 784Mi
volumeMounts:
- name: apmsocketpath
mountPath: /var/run/datadog
4 changes: 2 additions & 2 deletions k8s-manifests/storedog-app/deployments/discounts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ spec:
value: "true"
resources:
requests:
memory: "128Mi"
cpu: "100m"
memory: "128Mi"
limits:
memory: "256Mi"
cpu: "200m"
memory: "256Mi"
volumeMounts:
- name: apmsocketpath
mountPath: /var/run/datadog
7 changes: 4 additions & 3 deletions k8s-manifests/storedog-app/deployments/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ spec:
value: "true"
resources:
requests:
memory: "256Mi"
cpu: "100m"
cpu: 200m
memory: 384Mi
limits:
memory: "2Gi"
cpu: 600m
memory: 1Gi
volumeMounts:
- name: apmsocketpath
mountPath: /var/run/datadog
Expand Down
8 changes: 4 additions & 4 deletions k8s-manifests/storedog-app/deployments/nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ spec:
value: 'unix:///var/run/datadog/apm.socket'
resources:
requests:
memory: "128Mi"
cpu: "100m"
cpu: "50m"
memory: "64Mi"
limits:
memory: "256Mi"
cpu: "200m"
cpu: "100m"
memory: "128Mi"
volumeMounts:
- name: apmsocketpath
mountPath: /var/run/datadog
8 changes: 4 additions & 4 deletions k8s-manifests/storedog-app/deployments/worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ spec:
value: "true"
resources:
requests:
memory: "512Mi"
cpu: "250m"
cpu: "100m"
memory: "384Mi"
limits:
memory: "2Gi"
cpu: "1000m"
cpu: "300m"
memory: "512Mi"
volumeMounts:
- name: apmsocketpath
mountPath: /var/run/datadog
11 changes: 9 additions & 2 deletions k8s-manifests/storedog-app/statefulsets/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metadata:
name: postgres
labels:
tags.datadoghq.com/env: ${DD_ENV}
tags.datadoghq.com/service: store-db
tags.datadoghq.com/service: db
tags.datadoghq.com/version: "15.0"
spec:
serviceName: postgres
Expand All @@ -29,7 +29,7 @@ spec:
labels:
app: postgres
tags.datadoghq.com/env: ${DD_ENV}
tags.datadoghq.com/service: store-db
tags.datadoghq.com/service: db
tags.datadoghq.com/version: "15.0"
annotations:
ad.datadoghq.com/postgres.logs: '[{"source": "postgresql", "auto_multi_line_detection":true}]'
Expand Down Expand Up @@ -58,6 +58,13 @@ spec:
secretKeyRef:
name: storedog-secrets
key: POSTGRES_PASSWORD
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "300m"
memory: "256Mi"
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
Expand Down
19 changes: 19 additions & 0 deletions k8s-manifests/storedog-app/statefulsets/redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,31 @@ spec:
containers:
- name: redis
image: redis:6.2-alpine
command: ["redis-server"]
args: ["/etc/redis/redis.conf"]
ports:
- containerPort: 6379
name: redis
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "300m"
memory: "256Mi"
volumeMounts:
- name: redis-data
mountPath: /data
- name: redis-config
mountPath: /etc/redis
readOnly: true
volumes:
- name: redis-config
configMap:
name: redis-config
items:
- key: redis.conf
path: redis.conf
volumeClaimTemplates:
- metadata:
name: redis-data
Expand Down