Briefly describe the persistence, master-slave structure and pipeline of Redis

From "Redis Combat"

Persistence

There are two persistence methods that can be used together.

RDB

Introduction: snapshot, all data is written to the hard disk at a certain moment.
Use: Copy the snapshot to other servers for backup and restart the server.

Creation method:

  1. BGSAVE command (Windows does not support): Redis will fork a child process, and then the child process writes the snapshot to the hard disk, and the parent process continues to process new commands. Generally, 30%-45% of the memory is reserved for executing commands and creating a buffer for recording write commands.
  2. SAVE command: No new commands will be accepted until the snapshot is created, which has the advantage of saving memory.
  3. sava A BWhen there are B writes in the configuration file within A second, perform bgsave.
  4. When Redis receives a SHOUTDOWN or TERM signal.

performance:

  • This persistence method can be used when several GB.
  • Every time a process occupies 1G, the creation of sub-processes will increase by 10-20 milliseconds, and the virtual machine needs to increase the time by 200-300 milliseconds. For example, the Redis process occupies 20G of memory, creating a child process on standard hardware will cause a pause of 200-400 milliseconds, and the Xen virtual machine will pause for 4-6 seconds. Of course, it will take more time to write to the hard disk after creating the child process.

AOF

When executing a write command, copy the command to the hard disk.

Synchronization frequency:

  • always every command (may reduce SSD lifespan)
  • everysec Once per second (recommended, Redis performance is almost unaffected)
  • no no automatic synchronization

Problem:
It takes up a lot of space and can be rewritten with the BGREWRITE command (this command is also performed through a subprocess). It should be noted that it will cause problems when several G old files are deleted after rewriting.

master-slave structure

copy

In order to improve the load, and the reliability of the system. Command: slaveof no one,slaveof host port, only master-slave replication, master-master replication is not supported.

Process:
insert image description here
If there is a new slave server connected to the master server, if step 3 has not been executed, all slave servers receive the same snapshot and buffer write commands.
Otherwise, perform steps 1-5 again.

master-slave chain

If reading is significantly more than writing, and the number of read requests far exceeds the problem that a Redis server can solve. As the load increases, the master node may not be able to update all servers quickly, and users can use the middle layer to share the replication work, as shown in the figure below
insert image description here

Consistency\Performance

affairs

Format

MULTI
中间业务代码
EXEC

The commands between MULTI and EXEC will not be disturbed by other clients during execution, and the bottom layer improves performance through pipeline.

assembly line

Send multiple commands at once to reduce the number of communications, thereby reducing latency.

insert image description here
insert image description here

performance bottleneck

You can use the redis-benchmark tool to test the Redis performance of the server.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44532671/article/details/122932776