This commit is contained in:
Your Name
2025-07-24 16:06:20 +08:00
parent 7859803df5
commit 85af933847
+61 -49
View File
@@ -40,34 +40,31 @@ let
# High-performance settings # High-performance settings
settings = { settings = {
# Memory and performance optimizations # Memory and performance optimizations
maxclients = 65000; maxclients = mkForce 65000;
timeout = 0; # Never timeout connections timeout = mkForce 0; # Never timeout connections
tcp-keepalive = 60; tcp-keepalive = mkForce 60;
tcp-backlog = 511; tcp-backlog = mkForce 511;
# Disable slow operations for performance # Disable slow operations for performance
slowlog-log-slower-than = -1; # Disable slow log slowlog-log-slower-than = mkForce (-1); # Disable slow log
# Memory optimization # Memory optimization
maxmemory-policy = "noeviction"; # Don't evict keys maxmemory-policy = mkForce "noeviction"; # Don't evict keys
# Network optimizations # Network optimizations
"tcp-nodelay" = "yes"; tcp-nodelay = mkForce "yes";
# Hash optimizations for speed # Hash optimizations for speed
hash-max-ziplist-entries = 512; hash-max-ziplist-entries = mkForce 512;
hash-max-ziplist-value = 64; hash-max-ziplist-value = mkForce 64;
list-max-ziplist-size = -2; list-max-ziplist-size = mkForce (-2);
set-max-intset-entries = 512; set-max-intset-entries = mkForce 512;
zset-max-ziplist-entries = 128; zset-max-ziplist-entries = mkForce 128;
zset-max-ziplist-value = 64; zset-max-ziplist-value = mkForce 64;
# Disable key expiration notifications for performance
notify-keyspace-events = "";
# Cluster optimizations # Cluster optimizations
cluster-require-full-coverage = "no"; # Allow partial cluster operation cluster-require-full-coverage = mkForce "no"; # Allow partial cluster operation
cluster-allow-reads-when-down = "yes"; cluster-allow-reads-when-down = mkForce "yes";
}; };
}; };
}) (range 0 (masters - 1))); }) (range 0 (masters - 1)));
@@ -95,25 +92,24 @@ let
appendOnly = false; appendOnly = false;
settings = { settings = {
maxclients = 65000; maxclients = mkForce 65000;
timeout = 0; timeout = mkForce 0;
tcp-keepalive = 60; tcp-keepalive = mkForce 60;
tcp-backlog = 511; tcp-backlog = mkForce 511;
slowlog-log-slower-than = -1; slowlog-log-slower-than = mkForce (-1);
maxmemory-policy = "noeviction"; maxmemory-policy = mkForce "noeviction";
"tcp-nodelay" = "yes"; tcp-nodelay = mkForce "yes";
hash-max-ziplist-entries = 512; hash-max-ziplist-entries = mkForce 512;
hash-max-ziplist-value = 64; hash-max-ziplist-value = mkForce 64;
list-max-ziplist-size = -2; list-max-ziplist-size = mkForce (-2);
set-max-intset-entries = 512; set-max-intset-entries = mkForce 512;
zset-max-ziplist-entries = 128; zset-max-ziplist-entries = mkForce 128;
zset-max-ziplist-value = 64; zset-max-ziplist-value = mkForce 64;
notify-keyspace-events = ""; cluster-require-full-coverage = mkForce "no";
cluster-require-full-coverage = "no"; cluster-allow-reads-when-down = mkForce "yes";
cluster-allow-reads-when-down = "yes";
# Replica-specific settings # Replica-specific settings
replica-read-only = "no"; # Allow writes to replicas in cluster mode replica-read-only = mkForce "no"; # Allow writes to replicas in cluster mode
}; };
}; };
}) (range 0 (replicasPerMaster - 1)) }) (range 0 (replicasPerMaster - 1))
@@ -185,24 +181,40 @@ in
# System-wide performance optimizations # System-wide performance optimizations
boot.kernel.sysctl = { boot.kernel.sysctl = {
# Network optimizations # Network optimizations
"net.core.somaxconn" = "65535"; "net.core.somaxconn" = mkForce "65535";
"net.core.netdev_max_backlog" = "5000"; "net.core.netdev_max_backlog" = mkForce "5000";
"net.ipv4.tcp_max_syn_backlog" = "65535"; "net.ipv4.tcp_max_syn_backlog" = mkForce "65535";
"net.ipv4.tcp_fin_timeout" = "30"; "net.ipv4.tcp_fin_timeout" = mkForce "30";
"net.ipv4.tcp_keepalive_time" = "1200"; "net.ipv4.tcp_keepalive_time" = mkForce "1200";
"net.ipv4.tcp_keepalive_intvl" = "15"; "net.ipv4.tcp_keepalive_intvl" = mkForce "15";
"net.ipv4.tcp_keepalive_probes" = "5"; "net.ipv4.tcp_keepalive_probes" = mkForce "5";
# Memory optimizations # Memory optimizations
"vm.swappiness" = "1"; "vm.swappiness" = mkForce "1";
"vm.overcommit_memory" = "1"; "vm.overcommit_memory" = mkForce "1";
"vm.dirty_background_ratio" = "5"; "vm.dirty_background_ratio" = mkForce "5";
"vm.dirty_ratio" = "10"; "vm.dirty_ratio" = mkForce "10";
# File system optimizations # File system optimizations
"fs.file-max" = "2097152"; "fs.file-max" = mkForce "2097152";
}; };
# System-wide ulimit settings for Redis
security.pam.loginLimits = [
{
domain = "*";
type = "soft";
item = "nofile";
value = "1048576";
}
{
domain = "*";
type = "hard";
item = "nofile";
value = "1048576";
}
];
# Service-level optimizations for all Redis instances # Service-level optimizations for all Redis instances
systemd.services = systemd.services =
let let
@@ -213,8 +225,8 @@ in
) (range 0 (cfg.masters - 1))); ) (range 0 (cfg.masters - 1)));
serviceConfig = { serviceConfig = {
# Resource limits # Resource limits - set much higher for Redis cluster
LimitNOFILE = "65535"; LimitNOFILE = "1048576";
LimitNPROC = "65535"; LimitNPROC = "65535";
LimitMEMLOCK = "infinity"; LimitMEMLOCK = "infinity";