Home  >  Article  >  Database  >  redis performance optimization method

redis performance optimization method

尚
forward
2020-05-15 09:20:563423browse

redis performance optimization method

1. Redis deployment structure optimization suggestions

1. Master does not do AOF or RDB persistence, and Slave does AOF persistence. It is recommended to do RDB persistence at the same time

2. All Masters increase Slave

3. The Master can mount no more than 2 Slaves, using the M-S-S method. If you want to ensure high availability, that is, master-slave switching, you can use the Keepalived mechanism.

Note: The above are suggestions based on the unreasonable Redis deployment structure. We also refer to the Redis optimization solutions in Sina Weibo and Taobao architecture. Give

2. Redis configuration optimization suggestions

1.tcp-keepalive 60

Prevent the connection from being disconnected due to a command execution taking too long to reach the timeout timeout. And can improve the detection of connection errors.

2.stop-writes-on-bgsave-error no

Stop writing data to the disk when an error occurs in the bgsave snapshot operation, so that subsequent write operations will Failed. In order not to affect subsequent write operations, the value needs to be changed to no.

3.rdbchecksum no

Checking the correctness of the RDB data will sacrifice 10% of the performance, so It is recommended to close.

4.auto-aof-rotate-max-size 20gb

auto-aof-rotate-max-total 4
auto-aof-rewrite-percentage 0 (关闭rewrite模式)

Change the AOF rewrite mode to rotate mode, that is, switch the AOF online real-time Rewrite function to offline operation , one AOF file is cut into multiple copies (similar to log cutting), which improves redis performance and improves memory utilization.

5.no-appendfsync-on-rewrite yes

Avoid IO blocking when newly modified data is flushed to the disk

Note: The above are optimization suggestions based on unreasonable Redis configuration

3. System kernel configuration optimization suggestions

1. AOF mode is turned on. In order to alleviate IO blocking
Edit /etc/sysctl.conf and add the following configuration:

vm.dirty_background_ratio = 5
vm.dirty_ratio = 10

Then sysctl -p makes the configuration file take effect.

2. Enabled RDB mode, in order to avoid Fork failure

Edit /etc/sysctl.conf, change vm.overcommit_memory=1,

Then sysctl -p to make the configuration file take effect

Remarks: The above are system kernel optimization suggestions based on test results

Follow-up plan:

The above are optimization suggestions from an architectural perspective. Subsequently, we will analyze whether the memory type is reasonable and cold from a business perspective. Whether the division of hot data is reasonable, etc.

Remarks:

Regarding the division of hot and cold data, you can use the following Redis command for statistical analysis:

OBJECT REFCOUNT This command is mainly used for debugging ( debugging), it can return the number of times the value corresponding to the specified key is referenced.

OBJECT ENCODING This command returns the internal representation used by the value corresponding to the specified key (Translator's Note: It can also be understood as the data Compression method).

OBJECT IDLETIME This command returns the idle time in seconds since the value corresponding to the specified key is stored (no request for read or write operations). This value returns the idle time in 10 seconds. Second level time, this may be improved in future implementations.

For more redis knowledge, please pay attention to the redis introductory tutorial column.

The above is the detailed content of redis performance optimization method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete