Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AOF and RDB backups in redis

Tags:

redis

This question is about Redis persistence.

I'm using redis as a 'fast backend' for a social networking website. It's a single server set up. I've been transferring PostgreSQL responsibilities to Redis steadily. Currently in etc/redis/redis.conf, the appendonly setting is set to appendonly no. Snapshotting settings are save 900 1, save 300 10, save 60 10000. All this is true for production and development both. As per production logs, save 60 10000 gets invoked heavily. Does this mean that practically, I'm getting backups every 60 seconds?

Some literature suggests using AOF and RDB backups together. Thus I was weighing in on turning appendonly on and using appendfsync everysec. For anyone who has had experience of both sides of the coin:

1) Will using appendonly on and appendfsync everysec cause a performance downgrade? Will it hit the CPU? The write load is on the high side.

2) Once I restart the redis server with these new settings, I'll still lose the last 60 secs of my data, correct?

3) Are restart times something to worry about? My dump.rdb file is small; ~90MB.

I'm trying to find out more about redis persistence, and getting my expectations right. Personally, I'm fine with losing 60s of data in the case of a catastrophe, thus whether I should use AOF is also something I'm pondering. Feel free to chime in. Thanks!

like image 783
Hassan Baig Avatar asked Oct 10 '16 07:10

Hassan Baig


People also ask

What is Redis AOF?

Redis Append Only File or AOF is a persistence mechanism that allows the Redis server to keep track and log every command executed on the server. These command logs can then be re-played when the server starts up, recreating the database to its original state.

Where does Redis store dump RDB?

rdb file in the /var/lib/redis/ directory. You'll want to update the permissions so the file is owned by the redis user and group: sudo chown redis:redis /var/lib/redis/dump.

How do I backup my Redis database?

Redis SAVE command is used to create backup of current redis database. The SAVE commands performs a synchronous save of the dataset producing a point in time snapshot of all the data inside the Redis instance, in the form of an RDB file. Simple string reply: The commands returns OK on success.

Which is the best way to achieve persistence in Redis?

Within Redis, there are two different ways of persisting data to disk. One is a method called snapshotting that takes the data as it exists at one moment in time and writes it to disk. The other method is called AOF, or append—only file, and it works by copying incoming write commands to disk as they happen.


1 Answers

Does this mean that practically, I'm getting backups every 60 seconds?

NO. Redis does a background save after 60 seconds, if there're at least 10000 keys have been changed. Otherwise, it doesn't do a background save.

Will using appendonly on and appendfsync everysec cause a performance downgrade? Will it hit the CPU? The write load is on the high side.

It depends on many things, e.g. disk performance (SSD VS HDD), write/read load (QPS), data model, and so on. You need do a benchmark with your own data in your specific environment.

Once I restart the redis server with these new settings, I'll still lose the last 60 secs of my data, correct?

NO. If you turn on both AOF and RDB, when Redis restarts, the AOF file will be used to rebuild the database. Since you config it to appendfsync everysec, you will only lose the last 1 second of data.

Are restart times something to worry about? My dump.rdb file is small; ~90MB.

If you turn on AOF, and when Redis restarts, it replays logs in AOF file to rebuild the database. Normally AOF file is larger then RDB file, and it might be slower than recovering from RDB file. Should you worry about that? Do a benchmark with your own data in your specific environment.

EDIT

IMPORTANT NOTICE

Assume that you already set Redis to use RDB saving, and write lots of data to Redis. After a while, you want to turn on AOF saving. NEVER MODIFY THE CONFIG FILE TO TURN ON AOF AND RESTART REDIS, OTHERWISE YOU'LL LOSE EVERYTHING.

Because, once you set appendonly yes in redis.conf, and restart Redis, it will load data from AOF file, no matter whether the file exists or not. If the file doesn't exist, it creates an empty file, and tries to load data from that empty file. So you'll lose everything.

In fact, you don't have to restart Redis to turn on AOF. Instead, you can use config set command to dynamically turn it on: config set appendonly yes.

like image 192
for_stack Avatar answered Oct 11 '22 13:10

for_stack