Home  >  Article  >  Database  >  Redis operation and maintenance buffer

Redis operation and maintenance buffer

齐天大圣
齐天大圣Original
2020-05-21 09:28:14188browse

Perhaps many developers think that Redis is very simple, and just mastering some APIs is enough. In fact, if used improperly, many problems will occur. Today, let’s talk about redis buffering. Redis provides input buffers and output buffers to the client, and provides corresponding APIs to view the monitoring buffers.

Input buffer

Redis provides an input buffer for each client. Its function is to send the input buffer from the client. The command is saved, and then Redis extracts the command from the input buffer and executes it.

The input buffer size provided by Redis for the client is limited and cannot exceed 1G of memory. If it exceeds, Redis will close the client.

The dangers of buffer overflow

The maximum input buffer of each client cannot exceed 1G. If it exceeds, the client will be Turning it off will cause problems with the application.

The size of the input buffer cannot be controlled by maxmory. When maxmory is set to 8G, when Redis has stored 4G data and the total size of the input buffer of all clients is 5G, data loss may occur. Key value obsolescence, OOM and other situations.

The reason for buffer overflow is that the processing speed of redis cannot keep up with the input speed of the buffer. A common situation is that the input buffer contains a large number of bigkeys or redis is blocked.

Monitoring

There are two ways to monitor the input buffer

  • The first method is Use the client list command to view the information of all currently connected clients

  • The second method is to view the overall information through the info clients command.

127.0.0.1:6379> client list
id=113430 addr=127.0.0.1:57244 fd=7 name= age=3115 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 events=r cmd=client
id=113432 addr=127.0.0.1:57250 fd=9 name= age=3099 idle=342 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=set
……

Among them, related to the input buffer are qbuf and qbuf-free, which respectively represent the size of the input buffer and the size of the remaining input buffer.

127.0.0.1:6379> info clients
# Clients
connected_clients:4
client_recent_max_input_buffer:2
client_recent_max_output_buffer:0
blocked_clients:0

client_recent_max_input_buffer indicates the size of the maximum input buffer.

These two methods have their own advantages and disadvantages:

  • client list can accurately monitor the situation of each client, but the execution speed is slow and may cause redis blocking. .

  • info clients executes quickly, but the analyzed data is relatively simple and cannot be accurate to each client, and it cannot display the total client input buffer size, only the largest one.

Output buffer

Redis also provides an output buffer. Like the input buffer, the output buffer It is also not controlled by maxmory.

But unlike the input buffer, the output buffer can be limited through the configuration file.

client-output-buffer-limit type hardlimit softlimit secords

  • type represents the client type

  • hardlimit The maximum value of the output buffer. If it exceeds the limit, it will be closed immediately.

  • sortlimit and seconds. When the sortlimit limit is exceeded for seconds, the client will be closed.

The default configuration of Redis is as follows:

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

Monitoring

And the method of monitoring the output buffer Likewise, client list and info clients will also be used.

The client list related to the output buffer are obl, oll, and omem, mainly looking at omem, which represents the size of the output buffer.

client_recent_max_output_buffer in info clients indicates the maximum output buffer size.

Their advantages and disadvantages are the same as mentioned before, so I won’t go into details here.

In addition, here is another command to close the client connection.

client kill ip:port

When an exception is found on the client, you can use this command to close the abnormal connection.

The above is the detailed content of Redis operation and maintenance buffer. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn