Skip to content

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 to 0, Redis background saves may fail under low memory conditions.^[600-developer-big-data-redis-redis-01-install.md]
  • Optimization: Set vm.overcommit_memory to 1.^[600-developer-big-data-redis-redis-01-install.md]
  • Implementation: Add vm.overcommit_memory = 1 to /etc/sysctl.conf and apply it immediately with sysctl 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 never to the kernel configuration file.^[600-developer-big-data-redis-redis-01-install.md]
  • Implementation: Run the command echo never > /sys/kernel/mm/transparent_hugepage/enabled as 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.somaxconn to 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=32768 in /etc/sysctl.conf and run sysctl -p to load the changes.^[600-developer-big-data-redis-redis-01-install.md]

Sources