Cassandra and Solid State Drives

32,069 views
31,528 views

Published on

Published in: Technology
4 Comments
68 Likes
Statistics
Notes
No Downloads
Views
Total views
32,069
On SlideShare
0
From Embeds
0
Number of Embeds
2,705
Actions
Shares
0
Downloads
479
Comments
4
Likes
68
Embeds 0
No embeds

No notes for slide

Cassandra and Solid State Drives

  1. 1. CASSANDRA & SOLIDSTATE DRIVESRick Branson, DataStax
  2. 2. FACTCASSANDRA’S STORAGEENGINE WAS OPTIMIZED FOR SPINNING DISKS
  3. 3. LSM-TREES
  4. 4. WRITE PATH
  5. 5. insert({ cf1: { row1: { col3: foo } } }) Client Cassandra On-Disk Node Commit Log{ cf1: { row1: { col1: abc } } } In-Memory Memtable for “cf1”{ cf1: { row1: { col2: def } } }{ cf1: { row1: { col1: <del> } } } row1 col1: [del] col2: “def” col3: “foo”{ cf1: { row2: { col1: xyz } } } row2 col1: “xyz”{ cf1: { row1: { col3: foo } } } COMMIT
  6. 6. In-Memory Memtable for “cf1” row1 col1: [del] col2: “def” col3: “foo” row2 col1: “xyz”SSTable SSTable SSTable SSTable 1 2 3 4 FLUSH
  7. 7. SSTable SSTable SSTable SSTable 1 2 3 4 SSTableSSTables are merged to maintain read performance COMPACT
  8. 8. X X X X SSTable SSTable SSTable SSTableSSTable New SSTable is streamed to disk and old SSTables are erased
  9. 9. TAKEAWAYS• All disk writes are sequential, append- only operations• On-disk tables (SSTables) are written in sorted order, so compaction is linear complexity O(N)• SSTables are completely immutable
  10. 10. TAKEAWAYS• All disk writes are sequential, append- only operations• On-disk tables (SSTables) are written in sorted order, so compaction is linear IMPORTANT complexity O(N)• SSTables are completely immutable
  11. 11. COMPARED• Most popular data storage engines rewrite modified data in-place: MySQL (InnoDB), PostgreSQL, Oracle, MongoDB, Membase, BerkeleyDB, etc• Most perform similar buffering of writes before flushing to disk• ... but flushes are RANDOM writes
  12. 12. SPINNING DISKS• Dirt cheap: $0.08/GB• Seek time limited by time it takes for drive to rotate: IOPS = RPM/60• 7,200 RPM = ~120 IOPS• 15,000 RPM has been the max for decades• Sequential operations are best: 125MB/ sec for modern SATA drives
  13. 13. THAT WAS THE WORLDIN WHICH CASSANDRA WAS BUILT
  14. 14. 2012: MLC NAND FLASH* • Affordable: ~$1.75/GB street • Massive IOPS: 39,500/sec read, 23,000/ sec write • Latency of less than 100µs • Good sequential throughput: 270MB/ sec read, 205MB/sec write • Way cheaper per IOPS: $0.02 vs $1.25* based on specifications provided by Intel for 300GB Intel 320 drive
  15. 15. WITH RANDOM ACCESSSTORAGE, ARE CASSANDRA’S LSM-TREES OBSOLETE?
  16. 16. SOLID STATE HASSOME MAJOR BUTS...
  17. 17. ... BUT• Cannot overwrite directly: must erase first, then write• Can write in small increments (4KB), but only erase in ~512KB blocks• Latency: write is ~100µs, erase is ~2ms• Limited durability: ~5,000 cycles (MLC) for each erase block
  18. 18. WEAR LEVELING is usedto reduce the number of total erase operations
  19. 19. WEAR LEVELING
  20. 20. WEAR LEVELINGErase Block
  21. 21. WEAR LEVELING
  22. 22. WEAR LEVELING
  23. 23. WEAR LEVELING Disk Page
  24. 24. WEAR LEVELING Write 1
  25. 25. WEAR LEVELING Write 1 Write 2
  26. 26. WEAR LEVELING Write 1 Write 2 Write 3
  27. 27. Remember: the whole block must be erased Write 1 Write 2 Write 3 How is data from only Write 2 modified?
  28. 28. Mark Garbage
  29. 29. Empty BlockMark Garbage Append Modified Data
  30. 30. Wait... GARBAGE?
  31. 31. THAT MEANS...
  32. 32. ... fragmentation,WHICH MEANS...
  33. 33. Garbage Collection!
  34. 34. GARBAGE COLLECTION• Compacts fragmented disk blocks• Erase operations drag on performance• Modern SSDs do this in the background... as much as possible• If no empty blocks are available, GC must be done before ANY writes can complete
  35. 35. WRITE AMPLIFICATION• When only a few kilobytes are written, but fragmentation causes a whole block to be rewritten• The smaller & more random the writes, the worse this gets• Modern “mark and sweep” GC reduces it, but cannot eliminate it
  36. 36. Torture test shows massive write performance drop-off for heavily fragmented driveSource: http://www.anandtech.com/show/4712/the-crucial-m4-ssd-update-faster-with-fw0009/6
  37. 37. Some poorly designed drives COMPLETELY fall apartSource: http://www.anandtech.com/show/5272/ocz-octane-128gb-ssd-review/6
  38. 38. Even a well-behaved drivesuffers significantly from the torture testSource: http://www.anandtech.com/show/4244/intel-ssd-320-review/11
  39. 39. Post-torture, all disk blockswere marked empty, and the “fast” comes back...Source: http://www.anandtech.com/show/4244/intel-ssd-320-review/11
  40. 40. “TRIM”• Filesystems don’t typically immediately erase data when files are deleted, they just mark them as deleted and erase later• TRIM allows the OS to actively tell the drive when a region of disk is no longer used• If an entire erase block is marked as unused, GC is avoided, otherwise TRIM just hastens the collection process
  41. 41. TRIM only reduces thewrite amplification effect, it can’t eliminate it.
  42. 42. THEN THERE’S LIFETIME...
  43. 43. AnandTech estimates that modern MLC SSDsonly last about 1.5 years under heavy MySQL load, which causes around 10x write amplification
  44. 44. REMEMBER THIS?
  45. 45. TAKEAWAYS• All disk writes are sequential, append- only operations• On-disk tables (SSTables) are written in sorted order, so compaction is linear complexity O(N)• SSTables are completely immutable
  46. 46. CASSANDRA ONLY WRITESSEQUENTIALLY
  47. 47. “For a sequential write workload, write amplification is equal to 1, i.e., there is no write amplification.”Source: Hu, X.-Y., and R. Haas, “The Fundamental Limitations of Flash Random Write Performance: Understanding, Analysis, and Performance Modeling”
  48. 48. THANK YOU. ~ @rbranson

×