On Tue, Jan 22, 2013 at 8:43 AM, Stephen O'Donnell
<
stephen....@gmail.com> wrote:
> Guys,
>
> I have been doing a bit of a evaluation of Redis for my own interests and to
> see if it would be good for a few applications where I work. Right now we
> use Oracle for just about everything.
>
> If I was to use Redis, I would be looking at a fairly large dataset. Would
> it be generally advised to run Redis as many small shards, or one big (say
> 64GB+) instance?
Redis really only uses 1-2 cores (the 2nd core during snapshot and/or
aof rewriting), so if you've got a really big machine, you're going to
be under-utilizing your processors. You can run multiple instances on
a single machine, or multiple instances on multiple machines. Also,
because of NUMA, running a single Redis instance on huge memory won't
be as fast as running smaller instances assigned to certain cores, or
running Redis on multiple machines.
> What problems have people run into with large Redis instances?
Most people run into problems where the snapshot and/or AOF gets to be
very large, creating a new snapshot or rewriting an old AOF takes a
long time, and loading during restart takes a long time. Multiple
smaller instances mitigate this generally through rotating
snapshots/rewrites (or having multiple machines, thus multiple disks).
As a point of data, when I was running a ~50 gig Redis instance in
EC2, snapshotting took roughly 20 minutes with BGSAVE (fork + write),
but only 3 minutes with SAVE (blocking all other operations). To deal
with this, we paused the world at 3AM every night for snapshot +
backup. Also, starting that 50 gig instance from scratch took roughly
20 minutes.
> One thing that worries me about a busy large instance is persistence. I have
> read about the AOF and RDB files. If I had a 64GB data set and a lot of
> changes, I don't think RDB files are going to give me the data persistence I
> would require. The AOF is going to get big fast, which will affect startup
> times, and I get the feeling that frequent rebuilds on a database of that
> size are going to be slow.
Yes and no. Depending on your data, you can expect on-disk RDB files
to be roughly 10-20% of your in-memory usage, and freshly rewritten
AOFs to be roughly the same size as a fresh RDB. If you've got enough
disk IO, you should be able to write the RDB and/or AOF reasonably
quickly. But you will still run into issues like I already mentioned.
> The other thing that worries me about large instances is creating slaves.
> Pushing 64GB of data to a slave is going to take a long time, and then if
> the slave goes down it will take a long time to recover too.
This is really going to be the killer for you. Even at a 1:10 ratio of
on-disk vs. in-memory storage, slaving will still be moving 6
gigabytes. At gigabit ethernet speeds, that's 48 seconds to transfer
the data, but still probably 10-20 minutes just to load the data from
the snapshot. In that time, your master will probably be collecting
millions of write commands to send to the slave, and may disconnect
the slave or crash after running out of memory, neither of which you
want.
> I also noted at comment in an earlier thread titled 'Durability' that
> stated:
>
>> If you decide to go the Redis route, please only use it
>> for data that you can lose (or recover from a primary data source).
>
> Do I take it from this that it is seem as best practice to use Redis as a
> semi-permeanant data store, but ensure the data is persisted elsewhere
> incase it needs to be recovered in the future?
It depends on your needs. The aforementioned 50 gig Redis instance I
mentioned earlier was a Twitter Analytics database. Everything was
stored there (including some task queues for subsequent fetches). We
did the daily snapshot and backup because we could recover 24 hours of
data in 8 hours by re-fetching from Twitter. And in the worst-case, if
we were to lose the entire database, we would lose some historical
data, but could regenerate "current" data within 7 days running at
full tilt.
I said what I said because financial data (of the kind that Square
has) is important. More important than ego. More important than "look
at this awesome stuff that people are using Redis for." If your data
is important enough not to lose, you can mitigate risks with sharding,
slaving, AOF, and backed up snapshots. But risk mitigation only goes
so far when you're talking about financial data. And the last thing
that I (and I hope anyone else here) wants is for someone making a
mistake, losing data stored in Redis, and blaming Redis for not
holding their hand enough to prevent that loss.
Redis is this crazy blend between a cache, a database, remote data
structure API, and an API for data modeling with your application. It
does things that no other database does. But it also does things that
others don't do. Understanding the power, and limitations, aren't
necessarily straightforward. Which is why I advise being conservative.
Regards,
- Josiah