Redis AOF and RDB

Redis AOF and RDB

    Redis is a memory database, in order to ensure that data is not lost after a power outage, you need to persist data in memory to the hard disk.

RDB persistence

All the data points to a certain time are stored on the hard disk

You can copy the snapshot to a different server in order to create a copy of the same data server

If the system fails, the data will be lost after the last snapshot is created

If a large amount of data, save a snapshot of a very long time

AOF persistence

The write command to the end of AOF file (Append Only File) of

Use AOF persistent need to set the synchronization options, thereby ensuring that the timing of the write command to synchronize files on the disk. This is because the file does not immediately sucked content is synced to disk, but the first store into the buffer, then the operating system to decide when synchronized to disk. The following synchronization options:

Options

Synchronization frequency

always

Each write command are synchronized

everysec

Sync once per second

no

Let the operating system to decide when to synchronize

always options would seriously reduce the performance of the server

everysec option is more appropriate, you can guarantee only lost about one second data if the system crashes, and Redis executed every second synchronization virtually no impact on the server;

no option does not give the server to bring much improvement, but also increase the number of system crashes data loss.

With the increase in server written request, AOF file will grow. Redis provides Characteristics of a rewrite of the AOF, you can remove redundant AOF file write command.

 

 

 

RDB:

Redis main process fork a child process , so that the child process to perform disk IO operations to be persistent.

RDB write data to a temporary file, after the end of persistence, persistence replace the previous file with the temporary files, data files represent data in a certain moment of redis.

However, RDB is a time lag for persistence of, redis between failure if persistent data within this period of time is lost (RDB biggest drawback, leading to the first priority is not suitable for the recovery program, if you rely RDB do first priority recovery program, it will lead to more loss of data).

Why is the child?

(Mainly out of consideration Redis performance, (1) Redis RDB persistence mechanism will block the main process, so that the primary process will not respond to client requests. Working model (2) Redis client request response is a single process and single thread, if you start a thread in the primary process, this will result in competitive conditions on the data, in order to avoid the use of locks degrade performance. that is why more than two points Redis to perform the RDB by initiating a process based on a)

   

AOF:

AOF is considered to be a simple log file, which records only the "change action" (eg: set / del, etc.), the "Operational Data +" by way of formatting instructions append (additional, sequential write disks, no disk addressing overhead, so efficiency is very high) to the end of the operation log file (usually set once per second) after the append operation returns (or has been written to the file to be written), only the actual data changes. "Log File" to save all the operation history; when the server requires data recovery, direct replay this log file, you can restore all of the operation.
But AOF files larger than RDB files, and the recovery is slow.

AOF If the file is too large, you can use BGREWRITEAOF command (BGrewriteAOF), optimization aof file

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/kexinxin/p/11795790.html