Upgrade to Pro — share decks privately, control downloads, hide ads and more …

NoSQL 大腸花

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for yunglin yunglin
January 17, 2015

NoSQL 大腸花

Avatar for yunglin

yunglin

January 17, 2015
Tweet

More Decks by yunglin

Other Decks in Technology

Transcript

  1. 議程 • NoSQL 經驗 • MongoDB 2.2, 2.4, 2.6 •

    CouchDB 1.2 • Cassandra 0.6, 0.7, 1.0 • Riak 1.?
  2. 前期參戰國 • Dynamo DB • Google AppEngine Datastore • Cassandra

    • CouchDB • MongoDB http://thechangelog.com/18/
  3. 盟國 • Column Store: Cassandra, HBase • Document Store: CouchDB,

    MongoDB • Key-Value Store: DynamoDB, Redis, Riak • Graph Store: Neo4J
  4. CAP

  5. ⼤大家都說不會掉資料 • 實測結果 • MongoDB: 47% Acked Data Lost! •

    Riak: 91% Ack lost!, 0.3% Unack found! • Cassandra: 28% Ack lost! 
 Cassandra/CRDT: 0% lost
  6. 發⽣生了什麼事?! • Failover Strategy: MongoDB. • When Primary down, the

    secondary will become new Primary. When old Primary is back online, it will replay the op-log on old Primary.
 
 But it won’t most of time !!!
  7. 發⽣生了什麼事?! • Failover Strategy: Riak. • 由下 N 個結點接收 Write.

    如果 N 個寫⼊入成功, 就會回傳成功,但是回傳失敗,即使只有⼀一個 成功,最終,這⼀一個 Write 會被寫到 N 份去。
 • Conflict Resolution: 如果對同⼀一個 Key 的寫⼊入有 衝突,Riak會回傳多個值,由 Client 來判斷怎麼 取捨 http://blog.monitis.com/20123/14/an-overview-of-riak-an-open-source-nosql-database/
  8. 發⽣生了什麼事?! • Failover Strategy: Cassandra. • 由下 N 個結點接收 Write.

    如果 N 個寫⼊入成功,就會 回傳成功,但是回傳失敗,即使只有⼀一個成功,最終, 這⼀一個 Write 會被寫到 N 份去。
 • Conflict Resolution: 如果對同⼀一個 Key 的寫⼊入有衝突, Timestamp 最⼤大的會獲勝. • Timestamp 是個不可靠的數值,因為你不能保證 Cluster 中所有機器的時間都是同步的。 http://blog.monitis.com/20123/14/an-overview-of-riak-an-open-source-nosql-database/
  9. Scalability? • 所有的 DB 都是實作⼀一樣的 Journal DB 機制。 • 所以所有的

    DB 在 EC2 m1.large 上,都是 11,000 write/sec. (Riak: 我只有 4000w/s)
  10. Schema-less • Schema 真的是問題嗎?請再問你⾃自⼰己三遍 • Schema 的危害是,Migrate 時可能會把 DB 鎖住,

    造成 Downtime
 • Schema-less 要做 migration ,是在 code 中做 read-repair. • 所以說你的程式碼中要⼀一直有有 V1->V2, V2->V3, V3->V4…. 的 migration code. http://techblog.netflix.com/2011/11/benchmarking-cassandra-scalability-on.html
  11. Schema-less • Dynamic Language ⽤用起來很爽 • var tweets = db.find(….)


    for tweet in tweets:
 print tweet.text • 可是我們是寫 Java 的
  12. Model class is Schema @Entity("employees") class Employee { // auto-generated,

    if not set (see ObjectId) @Id ObjectId id; // value types are automatically persisted String firstName, lastName; // only non-null values are stored Long salary = null; // by default fields are @Embedded Address address;
  13. 2nd Index. • Cassandra, Riak 對 AdHoc Query 的回應 •

    每個結點⾃自⼰己 Index ⾃自⼰己的資料。 • 所以 Index 的⼤大⼩小是無限的。
  14. 2nd Index. • Cassandra, Riak 對 AdHoc Query 的回應 •

    每個結點⾃自⼰己 Index ⾃自⼰己的資料。 • 所以 Index 的⼤大⼩小是無限的。 • 結果變成能夠承受的 Query 總量,是固定的。
  15. MongoDB • 最熱⾨門的 NoSQL • ⽀支援 AdHoc Query • ⽀支援

    Index on any field • ⽀支援 Sharding, Replication
  16. MongoDB 缺點 • ⽂文件的 Size • Index 的 Size 驚⼈人

    • 被 Index 有欄位⼤大⼩小的限制(1024 bytes) • 對變⾰革的適應能⼒力( 連結外部新來的資料或查 尋)