Memory: The New Disk

53
Memory: The New Disk Beuth Hochschule für Technik 2010-11-09

Transcript of Memory: The New Disk

Page 1: Memory: The New Disk

Memory: The New Disk

Beuth Hochschule für Technik2010-11-09

Page 2: Memory: The New Disk

Who?

• Tim Lossen / @tlossen

• Ruby developer

• backend developer at ....

Page 4: Memory: The New Disk

Challenge

Page 5: Memory: The New Disk

Requirements

• backend for facebook game

Page 6: Memory: The New Disk

Requirements

• backend for facebook game

• 1 mio. daily users

• 100 KB data per user

Page 7: Memory: The New Disk

Requirements

• peak traffic:

- 10.000 concurrent users

- 3.000 requests/second

Page 8: Memory: The New Disk

Requirements

• peak traffic:

- 10.000 concurrent users

- 3.000 requests/second

• write-heavy workload

Page 9: Memory: The New Disk

RelationalDatabase

Page 10: Memory: The New Disk

Scaling Reads

• caching (memcached)

Page 11: Memory: The New Disk

Scaling Reads

• caching (memcached)

• read-only slaves

- horizontal scaling

Page 12: Memory: The New Disk

Scaling Reads

• caching (memcached)

• read-only slaves

- horizontal scaling

• easy

Page 13: Memory: The New Disk

Scaling Writes

• limit: 1000 writes/second on EC2

Page 14: Memory: The New Disk

Scaling Writes

• limit: 1000 writes/second on EC2

• sharding

- split database into parts

Page 15: Memory: The New Disk

Scaling Writes

• limit: 1000 writes/second on EC2

• sharding

- split database into parts

• difficult

Page 16: Memory: The New Disk

Alternatives?

Page 17: Memory: The New Disk

Alternatives?

Cassandra

CouchDB

MongoDB

RedisRiak

Membase

BigTableSimpleDB

Hypertable

Page 18: Memory: The New Disk

Basics

Page 19: Memory: The New Disk

Relative Latency

Memory 1

SSD

Disk

Page 20: Memory: The New Disk

Relative Latency

Memory 1

SSD 1000

Disk

x 1000

Page 21: Memory: The New Disk

Relative Latency

Memory 1

SSD 1000

Disk 100 000

x 1000

x 100

Page 22: Memory: The New Disk

Pizza Delivery Time

Memory 30 minutes

SSD 3 weeks

Disk 5.5 years

x 1000

x 100

Page 23: Memory: The New Disk

“Memory is the new disk, disk is the new tape.”

— Jim Gray

Page 24: Memory: The New Disk

Rule of thumb

• random access = memory

• sequential access = disk

Page 25: Memory: The New Disk

Euro per GB

Memory 20

SSD 2

Disk 0.05

÷ 10

÷ 40

Page 26: Memory: The New Disk

Redis

Page 27: Memory: The New Disk

Architecture

• key-value-store

• in-memory database

- with virtual memory

Page 28: Memory: The New Disk

Durability

• full database dumps

Page 29: Memory: The New Disk

Durability

• full database dumps

• append-only log

Page 30: Memory: The New Disk

Killer Feature

• high (write) throughput

- 30 to 150 K operations / second

Page 31: Memory: The New Disk

Other Features

• interesting data structures

- lists, hashes, (sorted) sets

- atomic operations

Page 32: Memory: The New Disk

Our Setup

Page 33: Memory: The New Disk

Architecture

• single Redis master

- with virtual memory

- handles all reads / writes

Page 34: Memory: The New Disk

Architecture

• single Redis master

- with virtual memory

- handles all reads / writes

• single Redis slave

- as hot standby (for failover)

Page 35: Memory: The New Disk

Throughput

• redis-benchmark

- 60 K ops / s = 3.6 mio ops / m

Page 36: Memory: The New Disk

Throughput

• redis-benchmark

- 60 K ops / s = 3.6 mio ops / m

• monitoring (rpm, scout)

- ca. 10 ops per request

Page 37: Memory: The New Disk

Throughput

• redis-benchmark

- 60 K ops / s = 3.6 mio ops / m

• monitoring (rpm, scout)

- ca. 10 ops per request

• 200 K req / m = 2.0 mio ops / m ✔

Page 38: Memory: The New Disk

Capacity 1

• 100 KB / user (on disk)

• 10.000 concurrent users (peak)

Page 39: Memory: The New Disk

Capacity 1

• 100 KB / user (on disk)

• 10.000 concurrent users (peak)

• 1 GB memory

- (plus Redis overhead) ✔

Page 40: Memory: The New Disk

Capacity 2

• Redis keeps all keys in memory

• 10 mio. total users

• 20 GB / 100 mio. integer keys

Page 41: Memory: The New Disk

Capacity 2

• Redis keeps all keys in memory

• 10 mio. total users

• 20 GB / 100 mio. integer keys

• 2 GB memory for keys ✔

Page 42: Memory: The New Disk

Data model

• one Redis hash per user

- key: facebook id

Page 43: Memory: The New Disk

Data model

• one Redis hash per user

- key: facebook id

• store data as serialized JSON

- booleans, strings, numbers, timestamps ...

Page 44: Memory: The New Disk

Advantages

• efficient to swap user data in / out

Page 45: Memory: The New Disk

Advantages

• efficient to swap user data in / out

• turns Redis into “document db”

- atomic ops on parts

Page 46: Memory: The New Disk

Advantages

• efficient to swap user data in / out

• turns Redis into “document db”

- atomic ops on parts

• easy to dump / restore user data

Page 47: Memory: The New Disk

Advice

Page 48: Memory: The New Disk

Advice

• use the right tool for the job

Page 49: Memory: The New Disk

Advice

• use the right tool for the job

• avoid sharding

- as long as possible

Page 50: Memory: The New Disk

Advice

• use the right tool for the job

• avoid sharding

- as long as possible

• keep it simple

Page 51: Memory: The New Disk

Q & A

Page 52: Memory: The New Disk

Nosql Night Berlin

November 17, 19:30newthinking storeTucholskystr. 48