1

I am trying to slower down the start process of Redis, so that when we initiate the command to start redis server and at the same do

info persistence

It should give Loading:1, but right now I am getting

loading:0
rdb_changes_since_last_save:1024
rdb_bgsave_in_progress:0
rdb_last_save_time:1530558451
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1 
rdb_last_cow_size:0
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0
Nidhi Sharma
  • 431
  • 1
  • 5
  • 17
  • Enable persistence and jam in a few GB of data so that it'll take time for your instance to start. There's no way to delay it arbitrarily. It's intended to load as quickly as possible. – tadman Jul 06 '18 at 18:05
  • I am not sure if I understood what jam means, What i understood from the statement is that i should have data in some GB and thats how i can induce the delay. Correct me if i am getting it wrong? – Nidhi Sharma Jul 06 '18 at 18:13
  • I mean that if you insert enough data into Redis that it takes a few seconds to load it back in you can catch it in the loading state after boot. With no data Redis comes up too quickly to observe that intermediate state. A few gigabytes should be enough to keep it busy for a minute or two, but you may not need that much if you want just a short window. – tadman Jul 06 '18 at 18:56
  • Sure, Thanks !! – Nidhi Sharma Jul 06 '18 at 20:45

1 Answers1

1

I have to rewrite some parts of this answer due to new information I got with the hint from @ItamarHaber

If you have only RDB set up

You can safely issue INFO PERSISTENCE and get loading:1

Loading RDB snapshot of 2GB db (500mb on disk) takes 15 sec on my machine (just for reference).

If you have AOF set up

During start Redis replays operations (it may do a compaction, removing operations that overwrite same keys) to bring DB state to what you had before shutdown. What this means is you either can get a meaningful answer (like above) or this:

BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.

if you had some big LUA scripts in server history. So with this configuration you need to be aware of that or use competely different method of checking whether Redis is ready:

tail -f to the Redis log file and look for lines:

oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

and

Ready to accept connections

Everything in between is the time when Redis starts and loads saved data.

p.s. How to fill Redis with test data

Imaskar
  • 2,773
  • 24
  • 35
  • 1
    I'm sorry, but Redis doesn't "load from a LUA script" - that's just plain false. Perhaps *your* AOF had some scripts in it, which could explain your misunderstanding – Itamar Haber Jul 07 '18 at 14:39
  • It turns out, some of my experiments were misleading. 'Almost empty' 127 byte AOF did contain LUA code that generated test bd. And instead of loading RDB it re-generated it, despite I had complete snapshot at hand. I tried a 0-byte aof and Redis didn't even load RDB file for some reason. What's more interesting, for some reason Redis creates RDB file along with AOF, but never reads it. Even when I disable AOF, and restart Redis - it comes empty. – Imaskar Jul 07 '18 at 15:26
  • @ItamarHaber thanks for your correction (not the first time!). I'm still very surprised that Redis redos ALL commands despite having a full snapshot. – Imaskar Jul 07 '18 at 15:42
  • Ok, this was due to `aof-use-rdb-preamble` being off. But what is interesting, it doesn't help when on. It still runs LUA again. If I issue `BGREWRITEAOF`, AOF file become almost the same size as RDB. Not what I would expect. – Imaskar Jul 07 '18 at 16:00
  • the RDB preamble in AOF only captures the dataset at it's beginning. Any subsequent commands (e.g. EVAL) are added in AOF format (i.e. basically the command itself) – Itamar Haber Jul 08 '18 at 16:55
  • What is the beginning? Shouldn't it reset when rdb is saved? – Imaskar Jul 08 '18 at 20:44
  • No, it doesn't reset when RDB is saved, only when AOF is rewritten. – Itamar Haber Jul 11 '18 at 11:29