-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathredis.production.conf
More file actions
124 lines (104 loc) · 3.37 KB
/
redis.production.conf
File metadata and controls
124 lines (104 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Redis Configuration for ProStaff API - PRODUCTION
# Optimized for Sidekiq + Rails Cache + Rate Limiting
# This version enables AOF for better durability of Sidekiq jobs
# Network
bind 0.0.0.0
port 6379
timeout 300
tcp-keepalive 60
# General
daemonize no
supervised auto
loglevel notice
# Persistence - RDB Snapshots (for job queue persistence)
# Save after 15min if at least 1 key changed
save 900 1
# Save after 5min if at least 10 keys changed
save 300 10
# Save after 1min if at least 10000 keys changed
save 60 10000
# Persistence - AOF (Append Only File) - ENABLED for production
# Trade-off: slightly lower performance but better durability for critical jobs
appendonly yes
appendfilename "appendonly.aof"
# Fsync strategy: everysec is a good balance
# - always: safest but slowest
# - everysec: good balance (default)
# - no: fastest but least safe
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
# Memory Management
maxmemory 512mb
# LRU eviction for cache
maxmemory-policy allkeys-lru
# Lazy freeing for better performance under memory pressure (Redis 4+)
lazyfree-lazy-eviction yes
lazyfree-lazy-expire yes
lazyfree-lazy-server-del yes
replica-lazy-flush yes
# Performance
# Multiple DBs for separation
# NOTE: For high-traffic scenarios, consider separate Redis instances
# instead of multiple DBs for better isolation and performance
databases 16
# DB 0: Rack::Attack rate limiting
# DB 1: Sidekiq jobs
# DB 2: Rails cache
# Multi-threaded I/O (Redis 6+) - improves throughput on multi-core
io-threads 4
io-threads-do-reads yes
# Replication (if using master-slave)
replica-read-only yes
# Security
# requirepass will be set via command line in docker-compose
# Slow Log
# Log queries slower than 10ms
slowlog-log-slower-than 10000
slowlog-max-len 128
# Client Output Buffer Limits
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
# Monitoring & Stats
# Track expired events for monitoring Sidekiq jobs
notify-keyspace-events Ex
# Latency monitoring - log operations taking >100ms
latency-monitor-threshold 100
# Memory optimization
# Active defragmentation (Redis 4+) - helps with memory fragmentation
activedefrag yes
active-defrag-ignore-bytes 100mb
active-defrag-threshold-lower 10
active-defrag-threshold-upper 20
active-defrag-cycle-min 5
active-defrag-cycle-max 75
# Performance tuning
# Disable THP (Transparent Huge Pages) at OS level:
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# Add to docker-compose or host startup script
# Increase max clients for production traffic
maxclients 10000
# Memory policy tweaks for production
# These optimize memory for common Rails/Sidekiq workloads
# Tune based on your actual data patterns (use MEMORY DOCTOR)
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
# TCP backlog
# Increase if you see "dropped connections" in logs
# Also increase OS limit: sysctl net.core.somaxconn=65535
tcp-backlog 511
# Protected mode (security)
# Disabled when using bind 0.0.0.0 with requirepass
protected-mode no
# TLS/SSL Configuration (uncomment for secure connections)
# port 0
# tls-port 6379
# tls-cert-file /path/to/redis.crt
# tls-key-file /path/to/redis.key
# tls-ca-cert-file /path/to/ca.crt