Memory: The New Disk
-
Upload
tim-lossen -
Category
Technology
-
view
2.410 -
download
0
Transcript of Memory: The New Disk
![Page 1: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/1.jpg)
Memory: The New Disk
Beuth Hochschule für Technik2010-11-09
![Page 2: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/2.jpg)
Who?
• Tim Lossen / @tlossen
• Ruby developer
• backend developer at ....
![Page 3: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/3.jpg)
![Page 4: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/4.jpg)
Challenge
![Page 5: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/5.jpg)
Requirements
• backend for facebook game
![Page 6: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/6.jpg)
Requirements
• backend for facebook game
• 1 mio. daily users
• 100 KB data per user
![Page 7: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/7.jpg)
Requirements
• peak traffic:
- 10.000 concurrent users
- 3.000 requests/second
![Page 8: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/8.jpg)
Requirements
• peak traffic:
- 10.000 concurrent users
- 3.000 requests/second
• write-heavy workload
![Page 9: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/9.jpg)
RelationalDatabase
![Page 10: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/10.jpg)
Scaling Reads
• caching (memcached)
![Page 11: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/11.jpg)
Scaling Reads
• caching (memcached)
• read-only slaves
- horizontal scaling
![Page 12: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/12.jpg)
Scaling Reads
• caching (memcached)
• read-only slaves
- horizontal scaling
• easy
![Page 13: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/13.jpg)
Scaling Writes
• limit: 1000 writes/second on EC2
![Page 14: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/14.jpg)
Scaling Writes
• limit: 1000 writes/second on EC2
• sharding
- split database into parts
![Page 15: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/15.jpg)
Scaling Writes
• limit: 1000 writes/second on EC2
• sharding
- split database into parts
• difficult
![Page 16: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/16.jpg)
Alternatives?
![Page 17: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/17.jpg)
Alternatives?
Cassandra
CouchDB
MongoDB
RedisRiak
Membase
BigTableSimpleDB
Hypertable
![Page 18: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/18.jpg)
Basics
![Page 19: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/19.jpg)
Relative Latency
Memory 1
SSD
Disk
![Page 20: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/20.jpg)
Relative Latency
Memory 1
SSD 1000
Disk
x 1000
![Page 21: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/21.jpg)
Relative Latency
Memory 1
SSD 1000
Disk 100 000
x 1000
x 100
![Page 22: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/22.jpg)
Pizza Delivery Time
Memory 30 minutes
SSD 3 weeks
Disk 5.5 years
x 1000
x 100
![Page 23: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/23.jpg)
“Memory is the new disk, disk is the new tape.”
— Jim Gray
![Page 24: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/24.jpg)
Rule of thumb
• random access = memory
• sequential access = disk
![Page 25: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/25.jpg)
Euro per GB
Memory 20
SSD 2
Disk 0.05
÷ 10
÷ 40
![Page 26: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/26.jpg)
Redis
![Page 27: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/27.jpg)
Architecture
• key-value-store
• in-memory database
- with virtual memory
![Page 28: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/28.jpg)
Durability
• full database dumps
![Page 29: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/29.jpg)
Durability
• full database dumps
• append-only log
![Page 30: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/30.jpg)
Killer Feature
• high (write) throughput
- 30 to 150 K operations / second
![Page 31: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/31.jpg)
Other Features
• interesting data structures
- lists, hashes, (sorted) sets
- atomic operations
![Page 32: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/32.jpg)
Our Setup
![Page 33: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/33.jpg)
Architecture
• single Redis master
- with virtual memory
- handles all reads / writes
![Page 34: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/34.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/35.jpg)
Throughput
• redis-benchmark
- 60 K ops / s = 3.6 mio ops / m
![Page 36: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/36.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/37.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/38.jpg)
Capacity 1
• 100 KB / user (on disk)
• 10.000 concurrent users (peak)
![Page 39: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/39.jpg)
Capacity 1
• 100 KB / user (on disk)
• 10.000 concurrent users (peak)
• 1 GB memory
- (plus Redis overhead) ✔
![Page 40: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/40.jpg)
Capacity 2
• Redis keeps all keys in memory
• 10 mio. total users
• 20 GB / 100 mio. integer keys
![Page 41: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/41.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/42.jpg)
Data model
• one Redis hash per user
- key: facebook id
![Page 43: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/43.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/44.jpg)
Advantages
• efficient to swap user data in / out
![Page 45: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/45.jpg)
Advantages
• efficient to swap user data in / out
• turns Redis into “document db”
- atomic ops on parts
![Page 46: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/46.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/47.jpg)
Advice
![Page 48: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/48.jpg)
Advice
• use the right tool for the job
![Page 49: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/49.jpg)
Advice
• use the right tool for the job
• avoid sharding
- as long as possible
![Page 50: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/50.jpg)
Advice
• use the right tool for the job
• avoid sharding
- as long as possible
• keep it simple
![Page 51: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/51.jpg)
Q & A
![Page 52: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/52.jpg)
Nosql Night Berlin
November 17, 19:30newthinking storeTucholskystr. 48
![Page 53: Memory: The New Disk](https://reader038.fdocuments.in/reader038/viewer/2022103113/55492f5cb4c90547498c2974/html5/thumbnails/53.jpg)
Links
• "A Conversation with Jim Gray"
•redis.io
•tim.lossen.de
•wooga.com/jobs