summaryrefslogtreecommitdiffstats
path: root/src/health/guides/redis/redis_bgsave_slow.md
blob: 6a04bdf27ca83cfd533b06a0c29aa8f52b99da94 (plain)
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
### Understand the alert

This alert, `redis_bgsave_slow`, indicates that the duration of the ongoing Redis RDB save operation is taking too long. This can be due to a large dataset size or a lack of CPU resources. As a result, Redis might stop serving clients for a few milliseconds, or even up to a second.

### What is the Redis RDB save operation?

Redis RDB (Redis Database) is a point-in-time snapshot of the dataset. It's a binary file that represents the dataset at the time of saving. The RDB save operation is the process of writing the dataset to disk, which occurs in the background.

### Troubleshoot the alert

1. Check the CPU usage

Use the `top` command to see if the CPU usage is unusually high.

```bash
top
```

If the CPU usage is high, identify the processes that are consuming the most CPU resources and determine if they are necessary. Minimize the load by closing unnecessary processes.

2. Analyze the dataset size

Check the size of your Redis dataset using the `INFO` command:

```bash
redis-cli INFO | grep "used_memory_human"
```

If the dataset size is large, consider optimizing your data structure or implementing data management strategies, such as data expiration or partitioning.

3. Monitor the Redis RDB save operation

Use the following command to obtain the Redis statistics:

```bash
redis-cli INFO | grep "rdb_last_bgsave_time_sec"
```

Review the duration of the RDB save operation (rdb_last_bgsave_time_sec). If the save operation takes an unusually long time or fails frequently, consider optimizing your Redis configuration or improving your hardware resources like CPU and disk I/O.

4. Change the save operation frequency

To limit the frequency of RDB save operations, adjust the `save` configuration directive in your Redis configuration file (redis.conf). For example, to save the dataset only after 300 seconds (5 minutes) and at least 10000 changes:

```
save 300 10000
```

After modifying the configuration, restart the Redis service for the changes to take effect.

### Useful resources

1. [Redis Persistence](https://redis.io/topics/persistence)
2. [Redis configuration](https://redis.io/topics/config)