Redis aof file Too big problem

Source: Internet
Author: User

Recently installed a new Redis with version redis-3.2.5

The data disk is made of solid-state drives.

Previous use of ordinary hard disk, Redis log daily

Asynchronous AOF Fsync is taking too long (disk is busy?). Writing the AOF buffer without waiting for Fsync to complete, this could slow down Redis.

If you change the SSD, it's not reported.


It took 3 days to find aof files getting bigger.

-rw-r--r--1 root root 136672283898 Dec 9 08:50 appendonly_6379.aof

-rw-r--r--1 root root 5200941168 Dec 7 18:09 temp-rewriteaof-26452.aof

The Redis itself uses 19G of memory, but the AoF file reaches 128G

Every morning to get out of the disk to expand the capacity once, or the disk will be full, bored to death.

But this goes on, can not solve the problem, after all, is the cloud server, add money every day expansion is not good.


Later on the net, found there was a command bgrewriteaof that could optimize the aof file

The steps are as follows:

Get into Redis first.

Redis-cli-p 6379-h 127.0.0.1

127.0.0.1:6379>bgrewriteaof


Then go to the directory of AOF files and find one more file

-rw-r--r--1 root root 136672283898 Dec 9 08:51 appendonly_6379.aof

-rw-r--r--1 root root 5851018456 Dec 9 08:51 temp-rewriteaof-1927.aof

-rw-r--r--1 root root 5200941168 Dec 7 18:09 temp-rewriteaof-26452.aof


Wait a few minutes

View AoF file again

-rw-r--r--1 root root 22477825463 Dec 9 09:11 appendonly_6380.aof

-rw-r--r--1 root root 5200941168 Dec 7 18:09 temp-rewriteaof-26452.aof


has significantly reduced the

And then delete the temp-rewriteaof-26452.aof file, it's no longer available.


I suddenly found a problem

After the implementation of the BGREWRITEAOF, temp-rewriteaof and other files, it is no longer produced, good magic.


Reference related explanations:

Bgrewriteaof

Performs a aof file rewrite operation. Overrides create a volume-optimized version of the current AOF file.

Even if the bgrewriteaof execution fails, there will be no data loss because the old AOF file will not be modified until bgrewriteaof succeeds.

The override will only be triggered when no other persisted work is performed in the background, which means:

If a Redis child process is performing the save of the snapshot, the AOF override is scheduled (scheduled) until the save work is completed and the AOF override is performed. In this case, the return value of bgrewriteaof is still OK, but adds an additional piece of information stating that BGREWRITEAOF will not execute until the save operation is complete. In Redis 2.6 or later, you can use the INFO command to see if Bgrewriteaof is scheduled.

If there is already another AOF file rewrite in execution, then Bgrewriteaof returns an error, and the new BGREWRITEAOF request will not be scheduled until the next execution.

Starting with Redis 2.4, AOF overrides are triggered by Redis itself, and bgrewriteaof is only used to trigger rewrite operations manually.


I've already 3.2.5, and it looks like Redis didn't automatically trigger bgrewriteaof

Or do it on a regular basis every day.


wrote a script.

brgewriteaof.sh


The contents are as follows:

#!/bin/bash


/usr/local/redis/redis-cli-p 6379-h 127.0.0.1 bgrewriteaof


Add permissions

chmod 755 brgewriteaof.sh

Set task schedule, run 2 o'clock in the morning every day

0 2 * * */opt/brgewriteaof.sh



This article is from the "Falling Star" blog, make sure to keep this source http://xiao987334176.blog.51cto.com/2202382/1881015

Redis aof file Too big problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.