this is redis - feature and usecase

30
This is REDIS - Feature and USECASE

Upload: kris-jeong

Post on 10-May-2015

3.961 views

Category:

Technology


0 download

DESCRIPTION

The name of book "This is redis". Book summary and use case.

TRANSCRIPT

Page 1: This is redis - feature and usecase

This is REDIS- Feature and USECASE

Page 2: This is redis - feature and usecase

About Me

Kris jeong(정경석 )

Author a Book of REDIS ‘This is REDIS’ in korean

Software development Over 14 years. Web service dev.

Messaging server dev.

Recommendation dev.

Interested about NoSQLhttp://www.aladin.co.kr/shop/wproduct.aspx?ISBN=8968480591

Page 3: This is redis - feature and usecase

What is

REDIS is In-Memory Database

Variety data types

Support persistence

Key value based NoSQL

Page 4: This is redis - feature and usecase

IMDB(In-Memory DB)

Query Engine Query Engine

Storage Man-ager

Memory(Cache)

Disk Disk

Memory

In-Memory data storeDisk based data store

Speed

Durability Disk is optional

Page 5: This is redis - feature and usecase

Redis is cache server?

Not a cache server.

But, It can be.

Turn off Persistence.

Page 6: This is redis - feature and usecase

Running platform

https://github.com/MSOpenTech/redis

Page 7: This is redis - feature and usecase

Install and test

$ wget http://download.redis.io/redis-stable.tar.gz$ tar xvf redis-stable.tar.gz$ cd redis-stable$ make……done.

$ make test

※ CentOS 6.4 64bit

Page 8: This is redis - feature and usecase

Feature

Page 9: This is redis - feature and usecase

Super fast (TPS)

$ ./src/redis-benchmark --csv -d 1024"PING_INLINE","34602.07""PING_BULK","35971.22""SET","35211.27""GET","31347.96"…"LPUSH (needed to benchmark LRANGE)","32467.53""LRANGE_100 (first 100 elements)","4714.76""LRANGE_300 (first 300 elements)","1605.91""LRANGE_500 (first 450 elements)","1030.93""LRANGE_600 (first 600 elements)","735.13""MSET (10 keys)","22471.91"

※ CentOS 6.4 64bit, Core i5 [email protected]

Page 10: This is redis - feature and usecase

Feature - expire

Duration cache expire user:212:cart 259200

It will be expired 3 days later.

Specified time cache expireat user:212:item:sward 1388534400

It will be expired 2014/01/01

seconds

Unix timestamp

Page 11: This is redis - feature and usecase

Support data types

String

user:1:cart_info

{ "product": { "id": "2951", "name": "testing 01", "options": { "color": "red" }, "quantity": 4 }}

※ Up to 512MB

key value

Page 12: This is redis - feature and usecase

Support data types (cont.)

Hash

item:1:info

name bastard sword

min dam-age

13

max dam-age

20

durability 32/50

price 3500

durability 31/50

add a new value

field valueKey

Page 13: This is redis - feature and usecase

Support data types (cont.)

Hash

item:1:info

name bastard sword

min dam-age

13

max dam-age

20

durability 32/50

price 3500

name bastard sword

min dam-age

13

max dam-age

20

durability 31/50

price 3500

field valueKey

Page 14: This is redis - feature and usecase

Support data types (cont.)

List

user:1:message

how r you.hi~

bye.

add a new value

Key elements

Page 15: This is redis - feature and usecase

Support data types (cont.)

List

user:1:message

how r you.hi~ bye.

Key elements

Page 16: This is redis - feature and usecase

Support data types (cont.)

Set

user:1:friend

kris

mike

frank

martin

tom

chris

add a new value

Page 17: This is redis - feature and usecase

kris

mike

frank

martin

tom

chris

Support data types (cont.)

Set

user:1:friend

kris

mike

frank

martin

tom

Page 18: This is redis - feature and usecase

1 kris

91 mike

200 frank

250 martin

251 tom

Support data types (cont.)

Sorted Set

user:ranking

220 chris

add a new value

score valueKey

Page 19: This is redis - feature and usecase

1 kris

91 mike

200 frank

250 martin

251 tom

1 kris

91 mike

200 frank

220 chris

250 martin

251 tom

Support data types (cont.)

Sorted Set

user:ranking

score valueKey

Page 20: This is redis - feature and usecase

Feature – RDB(Snapshot)

Redis data

Redis instance

Dump file(Redis-.rdb)

When snapshot event raised

Data dumpto disk

Redis data size vs Physical memory size ratio

vm.overcommit_memory setting

Disk I/O rate for swap

Check point of Redis snapshot

Page 21: This is redis - feature and usecase

Feature – AOF(Append Only File)

Redis data

Redis instance

appendon-ly.aof

Command logging

Redis client

Data change command

Disk space

Restart time is slower than RDB

Check point of Redis aof

Page 22: This is redis - feature and usecase

Replication – Single slave

Redis cluster

Slave NodeMaster Node

Redis client

set key1 ‘test value’

set key1 ‘test value’

Replication

key1 test value key1 test value

Page 23: This is redis - feature and usecase

Replication – Multiple slave

Master Node

Redis cluster

Redis client

Write

Replication

Read

Slave Node 2

Slave Node 1

Slave Node 3

Page 24: This is redis - feature and usecase

Replication – Multiple slave (cont.)

Master Node

Redis cluster

Slave Node 2

Redis client

Write

Slave Node 1

Slave Node 3 Slave Node 4

1st Replication

2nd Replication

Redis client

Read

Page 25: This is redis - feature and usecase

Sharding – range

Shard 1

Master Node

User Key 1 ~ 100

User Key 1~50 User Key 51~100

Shard 2

Master Node

Slave Node Slave NodeSlave Node Slave Node

● Data range based data split

Page 26: This is redis - feature and usecase

Sharding - vertical

Shard 1

Master Node

User info Content

Shard 2

Master Node

Slave Node Slave NodeSlave Node Slave Node

● Schema based data split

Page 27: This is redis - feature and usecase

Key % Number of Shard(Key % 2)

Sharding - consistent hashing

Shard 1

Master Node

User Key 1 ~ 100

Shard 2

Master Node

Slave Node Slave NodeSlave Node Slave Node

● Key based data split

Page 28: This is redis - feature and usecase

Sharding Calc

Sharding – Redis client

Redis client

Shard 1 Shard N

Read/Write Read/Write

Redis does not support server-side sharding

Most Redis client support hash based sharding

Re sharding issue

Check point of Redis Sharding

Page 29: This is redis - feature and usecase

Useage

Daily logged in user count

Weekly logged in user count

List of Logged-in account at least once of week

PV/UV Calculation 1Billion user

Top 10 of news by click count

News list by popular by comment count

Most popular News list - Real time

Score based Top 10 ranker.

Recent user list

Real time gamers ranking

Page 30: This is redis - feature and usecase

Demo