Linux kernel parameters for Redis optimization¶
To ensure Redis operates efficiently and avoids stability issues under load, specific Linux kernel parameters should be tuned. These settings primarily affect memory management and TCP networking configurations.^[600-developer-big-data-redis-redis-01-install.md]
Memory Management¶
The vm.overcommit_memory parameter controls the kernel's behavior regarding memory overcommitment.
- Default behavior: When set to
0, the kernel checks if there is enough available memory to satisfy the request. If set to0, Redis background saves may fail under low memory conditions.^[600-developer-big-data-redis-redis-01-install.md] - Optimization: Set
vm.overcommit_memoryto1.^[600-developer-big-data-redis-redis-01-install.md] - Implementation: Add
vm.overcommit_memory = 1to/etc/sysctl.confand apply it immediately withsysctl vm.overcommit_memory=1.^[600-developer-big-data-redis-redis-01-install.md]
Transparent Huge Pages (THP)¶
Transparent Huge Pages is a Linux memory management feature that can negatively impact Redis performance.
- Issue: Having THP support enabled in the kernel will create latency and memory usage issues with Redis.^[600-developer-big-data-redis-redis-01-install.md]
- Optimization: Disable THP by writing
neverto the kernel configuration file.^[600-developer-big-data-redis-redis-01-install.md] - Implementation: Run the command
echo never > /sys/kernel/mm/transparent_hugepage/enabledas root. To make this change persistent across reboots, add the command to/etc/rc.local.^[600-developer-big-data-redis-redis-01-install.md]
Networking¶
The net.core.somaxconn parameter defines the maximum size of the listen queue (backlog) for socket connections.
- Issue: This parameter limits the number of connection requests that can be queued for processing. If Redis is configured with a TCP backlog higher than the system's
somaxconn(default is often 128), the effective limit is capped at the lower system value. If the server processes requests slowly and the queue fills up, new requests will be rejected.^[600-developer-big-data-redis-redis-01-install.md] - Optimization: Increase
net.core.somaxconnto a higher value (e.g.,32768) to allow for a larger connection backlog.^[600-developer-big-data-redis-redis-01-install.md] - Implementation: Add or modify
net.core.somaxconn=32768in/etc/sysctl.confand runsysctl -pto load the changes.^[600-developer-big-data-redis-redis-01-install.md]