Skip to content

Commit 90ba787

Browse files
authored
Merge pull request #3225 from kelsey-steele/kelste01/redis-tune-revise
Redis: refresh tuning guidance
2 parents 87d7849 + 0da22bb commit 90ba787

3 files changed

Lines changed: 143 additions & 68 deletions

File tree

content/learning-paths/servers-and-cloud-computing/redis_tune/_index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ title: Learn how to tune Redis
33

44
minutes_to_complete: 30
55

6-
who_is_this_for: This is an advanced topic for software developers who want to deploy Redis on Arm-based servers and follow best practices to get performance benefits.
6+
who_is_this_for: This is an advanced topic for software developers who want to tune Redis on Arm-based servers and evaluate performance-sensitive configuration settings.
77

88
learning_objectives:
99
- Learn about kernel parameters that can impact Redis performance
1010
- Learn about compiler and libraries that can impact Redis performance
11-
- Tune a Redis configuration file for deployment
11+
- Tune Redis server configuration for improved performance
1212

1313
prerequisites:
14-
- Cloud or bare-metal installation of an Redis file server
14+
- Cloud or bare-metal installation of a Redis server
1515
- Review [Learn how to deploy Redis](/learning-paths/servers-and-cloud-computing/redis/) if you do not already have Redis setup
1616

17-
author: Elham Harirpoush
17+
author: Elham Harirpoush, Kelsey Steele
1818

1919
### Tags
2020
skilllevels: Advanced
@@ -27,7 +27,7 @@ cloud_service_providers:
2727
armips:
2828
- Neoverse
2929
tools_software_languages:
30-
- Redis
30+
- Redis
3131
- Runbook
3232

3333
operatingsystems:
@@ -38,7 +38,7 @@ further_reading:
3838
title: Redis Documentation
3939
link: https://redis.io/docs/
4040
type: documentation
41-
41+
4242

4343

4444
### FIXED, DO NOT MODIFY

content/learning-paths/servers-and-cloud-computing/redis_tune/kernel_comp_lib.md

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,53 @@ weight: 2
44
layout: "learningpathall"
55
---
66

7-
In this section you can get an overview of the linux kernel, compiler and OpenSSL settings that impact the performance of Redis.
7+
This section gives an overview of Linux kernel, compiler, and OpenSSL settings that can impact Redis performance.
88

9-
## Kernel configuration
9+
## Kernel Configuration
1010

11-
The profile of requests made by clients will differ based on the use case. This means there is no one size fits all set of tuning parameters for Redis. Use the information below as general guidance to tune Redis.
11+
The request profile varies by use case, so there is no one-size-fits-all set of tuning parameters for Redis. Use the information below as a starting point, then measure the impact for your workload.
1212

1313
### Memory Management
1414

15-
The memory related kernel parameters can be changed either temporarily through the `/proc` file system or permanently using the `sysctl` command.
16-
To improve memory utilization on your system, use the following commands:
15+
Memory-related kernel parameters can be changed temporarily with `sysctl -w` or made persistent by adding them to a file under `/etc/sysctl.d/`.
16+
17+
Use the following commands to apply the settings immediately:
1718

1819
```console
19-
sudo echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
20-
sudo echo 'vm.swappiness=1' >> /etc/sysctl.conf
20+
sudo sysctl -w vm.overcommit_memory=1
21+
sudo sysctl -w vm.swappiness=1
2122
```
22-
Understand the parameters:
2323

24-
* `vm.overcommit_memory`:
25-
* Enabling overcommit_memory to avoid out of memory space issues. If the overcommit memory value is 0 then there is chance that Redis will get an OOM (out of memory) error.
26-
* `vm.swappiness`:
27-
* When the Redis server consuming high memory, configuring the swappiness to its lowest value could be helpful.
24+
To make the settings persistent across reboots, create a Redis-specific sysctl file:
25+
26+
```console
27+
printf "vm.overcommit_memory = 1\nvm.swappiness = 1\n" | sudo tee /etc/sysctl.d/99-redis.conf
28+
sudo sysctl --system
29+
```
30+
31+
`vm.overcommit_memory` should be set to `1` so Redis background save and rewrite operations are less likely to fail during `fork()`.
32+
33+
`vm.swappiness` controls how aggressively Linux swaps memory pages. A low value helps reduce Redis latency caused by paging under memory pressure.
2834

2935
### Transparent Huge Page
3036

31-
Redis by default will disable transparent huge page (THP) if it is enabled for Redis process to avoid latency problems. You should disable this parameter in case this config has no effect.
37+
Transparent Huge Pages (THP) can increase Redis latency and memory use, especially when Redis forks for RDB snapshots or AOF rewrite. Disable THP at the kernel level on systems used for Redis performance tuning.
38+
39+
Check the current THP setting:
3240

33-
The command to disable this setting is shown below:
41+
```console
42+
cat /sys/kernel/mm/transparent_hugepage/enabled
43+
```
44+
45+
Disable THP until the next reboot:
3446

3547
```console
36-
sudo echo never > /sys/kernel/mm/transparent_hugepage/enabled
48+
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
3749
```
3850

3951
### Linux Network Stack
4052

41-
The Linux Network stack settings can be changed in the `/etc/sysctl.conf` file, or by using the `sysctl` command.
53+
Linux network stack settings can be changed temporarily with `sysctl -w` or made persistent by adding them to a file under `/etc/sysctl.d/`.
4254

4355
Documentation on each of the parameters discussed below can be found in the [admin-guide](https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/sysctl/net.rst) and [networking](https://github.com/torvalds/linux/blob/master/Documentation/networking/ip-sysctl.rst) documentation within the Linux source.
4456

@@ -48,34 +60,39 @@ Run the command below to list all kernel parameters.
4860
sudo sysctl -a
4961
```
5062

51-
Shown below are the network stack settings used for performance testing.
63+
Shown below are network stack settings used for Redis performance tuning.
5264

5365
```console
5466
sudo sysctl -w net.core.somaxconn=65535
5567
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=65535
56-
5768
```
5869

59-
These settings open up the network stack to make sure it is not a bottleneck.
70+
These settings raise connection queue limits so the kernel is less likely to be the bottleneck during high connection churn.
6071

6172
* `net.core.somaxconn`:
62-
* This setting is used to select the maximum number of connections the kernel will allow.
73+
* This setting controls the maximum listen backlog the kernel allows.
6374
* If the Redis server is expected to support a large number of clients, it may be helpful to increase this parameter.
64-
* A value of 65535 is probably excessively large for production. In practice, this just needs to be large enough to support the peak number of connections that will be made.
75+
* The value should be at least as large as the Redis `tcp-backlog` setting.
76+
* A value of 65535 is probably too large for production. In practice, this only needs to support the expected peak connection backlog.
6577
* `net.ipv4.tcp_max_syn_backlog`:
66-
* This setting is used to select the maximum number of connection requests that are pending but not established yet.
67-
* A value of 65535 is probably excessively large for production. In practice, this just needs to be large enough to support the peak number of connection requests that will be made.
78+
* This setting controls the maximum number of connection requests that are pending but not established.
79+
* A value of 65535 is probably too large for production. In practice, this only needs to support the expected peak rate of new connection attempts.
6880

6981

70-
## Compiler Considerations
82+
## Compiler Considerations
7183

72-
The easiest way to gain performance is to use the latest version of GCC. Aside from that, the flag `-mcpu` and `-flto` can be used to potentially gain additional performance. Usage of these flags is explained in the [Migrating C/C++ applications](/learning-paths/servers-and-cloud-computing/migration/c/) section of the [Migrating applications to Arm servers](/learning-paths/servers-and-cloud-computing/migration/) learning path.
84+
If you build Redis from source, use a recent GCC version from your Linux distribution. Compiler flags such as `-mcpu` and `-flto` can change performance, but they should be tested against your workload before use. Usage of these flags is explained in the [Migrating C/C++ applications](/learning-paths/servers-and-cloud-computing/migration/c/) section of the [Migrating applications to Arm servers](/learning-paths/servers-and-cloud-computing/migration/) learning path.
7385

74-
If you need to understand how to configure a build of Redis. Please review the [build Redis from source](https://redis.io/docs/latest/operate/oss_and_stack/install/archive/install-redis/install-redis-from-source/).
86+
For Redis build instructions, review the [build Redis from source](https://redis.io/docs/latest/operate/oss_and_stack/install/archive/install-redis/install-redis-from-source/) documentation.
7587

76-
## OpenSSL Considerations
88+
## OpenSSL Considerations
7789

78-
Redis relies on [OpenSSL](https://www.openssl.org/) for cryptographic operations. Thus, the version of OpenSSL used with Redis (and the GCC version and switches used to compile it) can impact performance. Typically using the Linux distribution default version of OpenSSL is sufficient.
90+
Redis uses [OpenSSL](https://www.openssl.org/) for TLS. TLS adds encryption and integrity-check overhead, so it can reduce the maximum throughput of a Redis instance. Typically, the Linux distribution default OpenSSL version is sufficient.
7991

80-
However, it is possible to use newer versions of OpenSSL which could yield performance improvements. This is achieved by using the `--with-openssl` switch when configuring the Redis build. Point this switch to the directory that contains the source code of the version of OpenSSL you'd like to have Redis link to. The Redis build system takes care of the rest. There is also a `--with-openssl-opt` switch which allows you to add options to the build for OpenSSL.
92+
To build Redis with TLS support, install the OpenSSL development libraries for your distribution and build Redis with:
93+
94+
```console
95+
make BUILD_TLS=yes
96+
```
8197

98+
Only test a newer OpenSSL version if TLS is part of the workload. If clients connect without TLS, OpenSSL does not affect Redis command throughput.

0 commit comments

Comments
 (0)