Some time ago, the Development Environment reported that access to the redis server was very slow, and each request took several seconds. 2 ~ This will happen again in three days.
I checked the Linux performance and there is no problem. Pass
# Redis-cli -- latency
It is found that accessing redis is really slow. It takes several seconds to execute info. There are tens of thousands of clients connected with a parameter.
Redis> client list
We can see that many clients have a large age and have never been released. So I suspect it is related to this. Because the version is 2.8.6, I cannot kill all connections at once through the client. I can only write one program and kill it one by one (
CLIENT KILL addr:port
). However, the problem persists.
So I further checked the configuration file and found that shnapshot is enabled by default,
Save 900 1
Save 300 10
Save 60 10000
Because the cache is used for session storage, it is not recommended to store snapshots, especially when redis is a VM machine, which has a great impact on the overall performance.So refer to our Manual notes:
################################ Snapshot ####### ##########################
# Save data to the disk in the following format:
# Save <seconds> <changes>
# Indicates how long and how many update operations are performed, and the data is synchronized to the data file RDB.
# It is equivalent to triggering snapshot capturing by conditions, which can be used with multiple conditions
# For example, three conditions are set in the default configuration file.
# Save 900 1 900 seconds at least one key is changed
# Save 300 10 300 seconds at least 300 keys are changed
# Save 60 10000 at least 10000 keys are changed within 60 seconds
# Comments to all session cache servers that do not use snapshots
# Save 900 1
# Save 300 10
# Save 60 10000
After restarting redis, I watched for a month and did not report any performance problems.
In addition, if the pub/sub of the client is not used, we recommend that you refer to the following parameters to set the client connection timeout. If this parameter is not used after 300 milliseconds, the server will automatically close the connection, release resources. Disabled by default.
# Set the timeout time for client connection, in seconds. When the client does not send any commands during this period, close the connection.
#0: disable this setting.
#5 minutes are recommended.
Timeout 300
# TCP keepalive
# In Linux, the specified value (in seconds) is used to send ACKs. Note that closing the connection takes double time. The default value is 0.
# Recommended 60.
TCP-keepalive 60
Note:
Redis 2.8.12 can kill all related connections at one time through the client type.