Slide 1

Slide 1 text

Poga 2012.03.31 based on real story

Slide 2

Slide 2 text

Hi 你好 Hallo 안녕 ciao salut こんにちは

Slide 3

Slide 3 text

i Poga

Slide 4

Slide 4 text

i wear many hats

Slide 5

Slide 5 text

i wear many hats build products

Slide 6

Slide 6 text

Product released PARTY? Let’s

Slide 7

Slide 7 text

Database CPU Utilization

Slide 8

Slide 8 text

Performance Degrading = Unhappy User = Less Profit

Slide 9

Slide 9 text

Complex Queries Inefficient schema

Slide 10

Slide 10 text

Limited Time

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Just ADD it to your stack

Slide 13

Slide 13 text

Just ADD it to your stack Not Replace

Slide 14

Slide 14 text

Special Performance Simple In-memory Atomic

Slide 15

Slide 15 text

Special Performance Simple In-memory Atomic

Slide 16

Slide 16 text

Management Problem a.k.a. “We don’t have a MIS”

Slide 17

Slide 17 text

Dependency Feb 25, 2009 First public beta Oct 14, 2011 Redis 2.4 First external dependency jemalloc Mar 31, 2012

Slide 18

Slide 18 text

Installation Feb 25, 2009 First public beta Oct 14, 2011 Redis 2.4 First external dependency jemalloc Mar 31, 2012 make install make install

Slide 19

Slide 19 text

Stable

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Special Performance Simple In-memory Atomic

Slide 22

Slide 22 text

Special Performance Simple In-memory Atomic

Slide 23

Slide 23 text

In-Memory Memcached High Performance Simple Key-Value Redis In-Memory High Performance Data Structures Persistence Replication ...

Slide 24

Slide 24 text

Data Structures List, Set, Sorted Set, Hash, String http://redis.io/commands

Slide 25

Slide 25 text

Understand your problem http://nosql.mypopescu.com/post/18977451039/redis-guide-what-each-redis-data-type-should-be-used Every command in Redis is manipulating a data structure

Slide 26

Slide 26 text

Special Performance Simple In-memory Atomic

Slide 27

Slide 27 text

Special Performance Simple In-memory Atomic

Slide 28

Slide 28 text

=

Slide 29

Slide 29 text

http://redis.io/topics/benchmarks FAST for real

Slide 30

Slide 30 text

Special Performance Simple In-memory Atomic

Slide 31

Slide 31 text

No Race Condition every command in redis is atomic use redis as a incremental counter “There are very few systems that support an “increment and return” operation, and Redis is one of them (Oracle sequences are another).” http://nateware.com/2010/02/18/an-atomic-rant/

Slide 32

Slide 32 text

No Race Condition every command in redis is atomic Combine multiple command: still atomic! MULTI SET key 123 SET key2 456 EXEC Warning: Don’t confuse with transaction

Slide 33

Slide 33 text

Special Performance Simple In-memory Atomic

Slide 34

Slide 34 text

i

Slide 35

Slide 35 text

Did I make any changes to MySQL? NO It’s still our main database

Slide 36

Slide 36 text

Did I solve the problem? YES solve complex queries via Redis data structure

Slide 37

Slide 37 text

Happy Database Add Redis to stack

Slide 38

Slide 38 text

How? Sorted Set: Per user notification String: API request limiter String, List: Request logging List: Job Queue

Slide 39

Slide 39 text

Real World = Risk Persistence Replication Sharding

Slide 40

Slide 40 text

Persistence RDB AOF

Slide 41

Slide 41 text

RDB • Snapshot • Compact • .rdb file can be transfered to other backup system • Chances to lose data

Slide 42

Slide 42 text

AOF • logs of every write operation • durable • bigger file size

Slide 43

Slide 43 text

You want a degree of safety comparable to PostgreSQL? Just use BOTH

Slide 44

Slide 44 text

Replication Master Slave Slave Slave

Slide 45

Slide 45 text

Replication • Read-only salves • Save on slaves

Slide 46

Slide 46 text

Sharding • Memory is limited • Split data into multiple redis servers

Slide 47

Slide 47 text

Presharding Single Machine Redis instance Redis instance Redis instance Redis instance Redis instance Redis instance Redis instance Redis instance Redis instance Redis instance Multiple Machine

Slide 48

Slide 48 text

Some Case Study • Resque • Rubygems.org • Tumblr • Instagram

Slide 49

Slide 49 text

Resque High Performance Job Queue https://github.com/blog/542-introducing-resque

Slide 50

Slide 50 text

Rubygems.org http://www.scribd.com/doc/34269414/Redis-Persistence-Power feature switch API request limit Logging Job Queue

Slide 51

Slide 51 text

Tumblr http://engineering.tumblr.com/post/7819252942/staircar-redis-powered-notifications Per-user Notification 30,000 request/s per server

Slide 52

Slide 52 text

Instagram http://engineering.tumblr.com/post/7819252942/staircar-redis-powered-notifications Simple Key-value mapping 1/3 cost on hardware

Slide 53

Slide 53 text

Cross server temporary file sharing i Redis string is binary-safe

Slide 54

Slide 54 text

Future

Slide 55

Slide 55 text

Future Lua Scripting Watchdog

Slide 56

Slide 56 text

Lua Scripting Atomic Saving bandwidth between servers

Slide 57

Slide 57 text

Ruby Redis Sum up 200,000 values ... 200,000 times

Slide 58

Slide 58 text

Ruby Redis Sum up 200,000 values, with Lua scripting 1 request

Slide 59

Slide 59 text

Data Model Query Language Scripting MySQL Redis Relational Table SQL Data Structures Lua Lua

Slide 60

Slide 60 text

Watchdog Let Redis monitor itself Like slow queries in MySQL More information to diagnose problem

Slide 61

Slide 61 text

Bright Future Lua Scripting Watchdog

Slide 62

Slide 62 text

= Unique

Slide 63

Slide 63 text

Unique = Not replacing anyone Job security of other database

Slide 64

Slide 64 text

What will u get

Slide 65

Slide 65 text

More life less cost Happy User

Slide 66

Slide 66 text

Thank you question? @devpoga