NoSQL概論

E1923013dacab39eb231a2fffbf7b33c?s=47 UENISHI Kota
September 11, 2015

 NoSQL概論

High-level overview on NoSQL

E1923013dacab39eb231a2fffbf7b33c?s=128

UENISHI Kota

September 11, 2015
Tweet

Transcript

  1. NoSQL ֓࿦ 2015/9/11 DB Tech Showcase Sapporo Basho δϟύϯ᷂ɹ্੢߁ଠ

  2. ୭ʁ • @kuenishi • Github, Twitter, etc • ෼ࢄγεςϜྺ7೥ •

    Bashoδϟύϯͷํ͔Βདྷ·ͨ͠ • Riak CSͷ։ൃ • ࠷ۙ͸τϥϯβΫγϣϯʹڵຯ ͕͋Γ·͢
  3. Ξϯέʔτ •SQL͡Όͳ͍ͱϦϨʔγϣφϧͳσʔλϕʔ ε͸࡞Εͳ͍ʁ •ʮཧ࿦͔ΒֶͿσʔλϕʔε࣮ફೖ໳ʯΛಡ Μͩʁ •ʮNoSQLͷجૅ஌ࣝʯΛಡΜͩʁ •Dynamo? BigTable? Tandem?

  4. ΞδΣϯμ •NoSQLΑ͏Θ͔ΒΜʂԿʁʂͱ͍͏ਓͷͨΊʹɺ Կͳͷͬͯ࿩Λ͠·͢ •͍Ζ͍Ζ͋ͬͯΘ͔ΒΜʂͱ͍͏ਓͷͨΊʹ෼ྨ ࣠ʹ͍͓ͭͯ࿩͠·͢ •ͦͷଞɺ༩ଠ࿩Λ͠·͢

  5. Relational DBMS •Ұൠతʹ͸… •ෳ਺ͷΫϥΠΞϯτ͔ΒTCP/IPͰ઀ଓ͠ •ϦϨʔγϣφϧϞσϧΛ࣮༻Խͨ͠SQLͱ͍͏ݴޠΛΠϯλʔ ϑΣʔεͱ͠ •B+treeͱϒϩοΫΩϟογϡͱ͍͏σʔλߏ଄Λ࢖͍ɺ •WALͱB+treeͰӬଓԽΛ͠ʢϨϓϦέʔγϣϯ͸͠ͳ͍ʣɺ •MVCCͳͲͰฒߦੑ੍ޚΛߦ͏σʔλϕʔε؅ཧγεςϜ

  6. NoSQL? •Not Only? •ݴ༿ͱ͸ҟͳΔɺ2௨Γͷ࣮ଶ •A) σʔλϞσϧɺΠϯλʔϑΣʔεͱͯ͠SQLΛ࢖ͬͯ ͍ͳ͍ •B) طଘͷτϥϯβΫγϣϯॲཧٕज़Ͱ͸Ͱ͖ͳ͔ͬͨ͜ ͱΛ࣮ݱ͢ΔͨΊʹɺผٕज़Λ࠾༻ͨ͠

  7. SQLͰ͸ͳ͍ʁ •ϦϨʔγϣφϧϞσϧͰ͸ͳ͍ԿΒ͔ͷσʔλϞσϧ •σʔλදݱ΍ΫΤϦݴޠʹSQLΛ࢖Θͳ͍ •υΩϡϝϯτDB: “Semi-structured database” •Redis •KVS (Key-Value Store):

    ฆΒΘ͍͠
  8. Document DB •΋ͱ΋ͱͷࢥ૝: •͋ΒΏΔλΠϓͷυΩϡϝϯτΛอଘͯ͠ΫΤϦ Ͱ͖ΔΑ͏ʹ͠Α͏ •JSON, XML, PDF, etc… •ݱ࣮:

    ݁ہ… •KVS ʹ JSON + ΠϯσοΫε + ෼ࢄMapReduce
  9. ACIDͰ͸ͳ͍ʁ

  10. ACID •Atomicity •ߋ৽ͷ్தঢ়ଶ͕ݟ͑ͳ͍͜ͱ •Isolation •ଞͷਓ͕ߋ৽͍ͯ͠Δͷ͕ݟ͑ͳ͍͜ͱ •Key-Value StoreͳΒɺ୯ҰͷΤϯτϦΛϩοΫͯ͠ߋ৽͢Δͩ ͚ͳͷͰAtomicͩ͠Isolated!! ʢϗϯτʁʣ

  11. ACID •RDBͩͱ •ϦϨʔγϣϯಉ࢜ͷσʔλ͕੔߹͍ͯ͠Δ͜ͱ •෼ࢄτϥϯβΫγϣϯͯ͠΋σʔλ͕ෆ੔߹͠ͳ͍͜ͱ •ނোͯ͠΋੔߹ͨ͠ঢ়ଶͰϦΧόϦͰ͖Δ͜ͱ •NoSQLͩͱ •ϨϓϦέʔγϣϯͯ͠΋σʔλ͕ෆ੔߹͠ͳ͍͜ͱ •Key-Value StoreͳΒ…

  12. ACID •RDBͩͱ •ӬଓԽ͸σΟεΫʹॻ͍ͨΒऴΘΓ •σΟεΫյΕͨΒ஌ΒͶ •NoSQLͩͱ •σΟεΫյΕͯ΋ιϑτ΢ΣΞͰԿͱ͔͢Δ •ࣗ෼ͰϨϓϦέʔγϣϯ΋΍Δʂ

  13. εέʔϧΞ΢τʁ •σʔλͷۭؒΛԿΒ͔ͷϧʔϧʹଇͬͯ෼ׂ͢Δ •෼ׂͨ͠σʔλΛ෼ࢄͯ͠؅ཧ͢Δ •ϊʔυΛ૿΍͢ͱॲཧೳྗ΍༰ྔ͕૿͑Δʢʁʣ

  14. εέʔϧΞ΢τਤղ σʔλۭؒ ۭؒ෼ׂ

  15. B+Tree •Ωʔ΍ΠϯσοΫε͔Β O(log N) ҎԼͷίετͰ σʔλΛݟ͚ͭΔͨΊͷσʔλߏ଄ •εέʔϧΞ΢τ͢Δͱ… •͍͔ͭ͘ิ׬ʢ୅ସʣٕज़͕͋Δ •Consistent Hashing

    •γϟʔσΟϯά (Range Partitioning) •֊૚γϟʔσΟϯά
  16. εέʔϧΞ΢τͱ଱ނোੑ •Q. 1୆ͷϊʔυͷނো֬཰Λ p ͱ͢Δͱɺ n ୆ͷΫϥελ͕શͯ ਖ਼ৗಈ࡞͍ͯ͠Δ֬཰͸ʁ 1. 1

    - p^n 2. p^n 3. (1 - p)^n •εέʔϧ͕େ͖͍ͱɺͲ͔͕͜΄΅ඞͣյΕ͍ͯΔঢ়ଶʹͳΔ •෦෼ނো͕ى͖͍ͯͯ΋શମ͕ਖ਼͘͠ಈ࡞͢Δઃܭ͕ඞཁ •ϨϓϦέʔγϣϯʹΑΔࣗಈతͳϑΣΠϧΦʔόʔͳͲ͕ඞཁ
  17. ਖ਼ৗಈ࡞ͷ֬཰ n \ p 0.1 0.01 0.001 1 0.9 0.99

    0.999 10 0.348678440 0.904382075 0.990044880 100 0.000026561 0.366032341 0.904792147 1000 0 0.000043171 0.367695424 ※༗ޮ਺ࣈ…
  18. εέʔϧΞ΢τਤղ 2 σʔλۭؒ ෳ੡

  19. ӬଓԽͱ͸ •ܗ͋Δ΋ͷ͸͍͔ͭյΕΔ •ॾߦແৗʢେൠᔷᒒܦʣ •2ͭҎ্ͷίϐʔΛ͓࣋ͬͯ͘Ҏ֎ʹɺ σʔλΛӬٱʹอଘ͢Δํ๏͸ͳ͍ •ෳ੡ͷͳ͍σʔλϕʔε͸ͳ͍

  20. ෳ੡͸ඞͣ࡞ΒΕΔ •LANͷ޲͜͏Ͱ •SANͷ޲͜͏Ͱ •ւͷ޲͜͏Ͱ •ނো୯Ґ͕ඞͣ෼͔Ε ͍ͯΔ (C) Evan Amos

  21. ނোͯ͠΋ಈ࡞ܧଓ͢Δෳ੡ •Ͳ͏͍͏ނোϞσϧΛલఏʹͯ͠Ϩϓ ϦέʔγϣϯΛ૊Μ͔͕ͩॏཁ •Fail-stopΛલఏʹͯ͠͸͍͚ͳ͍ •ʮյΕ͔͚ͷRadioʯ •͍ΘΏΔαΠϨϯτނো •ωοτϫʔΫͷ੾அɺॠஅ •Disk Hiccup (C)

    Evan Amos
  22. ωοτϫʔΫͷ෼அ •෼அͨ͠ΒɺͲͪΒ͕ਖ਼͠ ͍͔ܾΊͳ͚Ε͹͍͚ͳ͍ •ϚχϡΞϧͰհೖ͢Ε͹ܾ ΊΒΕΔʢ͔΋͠Εͳ͍ʣ •ࣗಈԽ͢Δʹ͸ɺωοτϫʔ Ϋ͕੾Εͯ΋σʔλΛ੔߹ ͤ͞Δෳ੡ٕज़͕ඞཁ ? ?

    (C) Evan Amos
  23. ෳ੡ͷٕज़ ෳ੡ͷλΠϓ ނোͳͲͷલఏ Master-slave ಉظ ωοτϫʔΫ͕ނোͨ͠Βࢭ·Δ Master-slave ඇಉظ ωοτϫʔΫ͕ނোͨ͠Β σʔλ͕ෆ੔߹͢Δ͔΋

    Consensus (Strong Consistency) ωοτϫʔΫ͕ނোͨ͠ΒҰ෦ಈ࡞ Eventual Consistency ωοτϫʔΫ͕ނোͯ͠΋׬શಈ࡞
  24. ෳ੡Ͱ͸ͳ͍σʔλͷ੔߹ੑ •εέʔϧΞ΢τ͢Δͱɺผϊʔυ্ͷ ผͷσʔλΛ੔߹ͨ͠ঢ়ଶͰߋ৽͠ͳ ͚Ε͹ͳΒͳ͍ •෼ࢄͨ͠ΠϯσοΫεͷߋ৽ •֎෦Ωʔͷߋ৽ •τϦΨʔͷॲཧ

  25. εέʔϧΞ΢τਤղ 3 ςʔϒϧ ΠϯσοΫε or FKey or else

  26. ෳ੡Ͱ͸ͳ͍σʔλͷ੔߹ੑ อো •2PC (or ෼ࢄϩοΫ) •ϩοΫΛ࣋ͬͨ··ϊʔυ͕ނোͨ͠ͱ͖ͷѻ͍ •Cluster-wideͰҰ؏ͯ͠୯ௐ૿Ճ͢ΔԿΒ͔ͷ੔਺Λੜ੒͢Ε ͹ɺTSO΍MVCCΛ࣮૷Ͱ͖Δ •λΠϜελϯϓ …

    ࣌ܭͷಉظΛอো͢Δํ๏͕ࣗ໌Ͱ͸ͳ͍ •IDΛൃߦ͢ΔϚελʔϊʔυ … SPoF •͜͜·ͰͪΌΜͱ΍͍ͬͯΔNoSQL੡඼͸΄ͱΜͲͳ͍
  27. NoSQLͷऴΘΓ •RDBMSͰղ͚ͳ͔ͬͨ໰୊͕͍͔ͭ͘ղ͚ͨͷͰʮ΍ͬͺΓSQL͕΄͍͠ʯ ʮ׳Εٕͨज़ऀ͕ଟ͍ͷͰʯ •ϦϨʔγϣφϧϞσϧʹଇ͍ͯ͠ͳ͍σʔλͰ΋SQLͰΫΤϦΛॻ͚ͯ͠·͏ •͍͔ͭ͘ͷNoSQL੡඼͸ɺτϥϯβΫγϣϯ؅ཧΛͦͦ͜͜ʹ SQL(-like ͳ) ΠϯλʔϑΣʔεΛఏڙͭͭ͋͠Δ •CQL, N1QL,

    etc.. •OLAP޲͚ͷMPPΤϯδϯ͸SQL͕ඪ४ •Impala, Drill, PrestoDB, Calcite
  28. 2ͭͷٕज़෼໺ •ΫΤϦॲཧ •RDBMSͰ͸SQL •RDBMSͰͳͯ͘΋SQL •τϥϯβΫγϣϯॲཧ •ACIDΛ࣮ݱ͍ͯ͠ΔRDBMS •෼ࢄ͍ͯͯ͠΋ACIDΛ໨ࢦ͍ͯ͠Δ

  29. Summary •ʢੲ͸ʣNoSQL ͱ͸ɺطଘͷσʔλϕʔεٕज़Λ1͔Βݟͳ ͓ͯ͠ɺRDBMSͰ͸Ͱ͖ͳ͔ͬͨ͜ͱΛୡ੒͠Α͏ͱͨ͠Ұ ࿈ͷࢼΈ •ϦϨʔγϣφϧϞσϧɺB+treeɺϨϓϦέʔγϣϯ •ʢࠓ͸ʣ΋͏Կ͕ͳΜ͔ͩ෼͔Βͳ͍͘Β͍ଟ༷Խ •ٕज़తͳ؍఺ʢ໰୊ͷ෼ྨʣ •εέʔϧΞ΢τɺ଱ނোੑɺ੔߹ੑʢ΋ɺ͋ΔΑ