Upload
cloudian
View
4.365
Download
1
Embed Size (px)
DESCRIPTION
2013年7月30日開催、JDMC分科会講義資料。 2012年4月発売「NOSQLの基礎知識 ビッグデータを活かすデーターベース技術:リックテレコム刊」からの更新情報も追加しています。
Citation preview
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識河野 達也 Tatsuya KawanoRampD ソフトウェアエンジニアクラウディアン株式会社
2013年年7月30日日本データマネジメントコンソーシアム(JDMC)研究会テーマ2emsp 第2回オープン研究会
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License2
本日の内容
bullNOSQLの特徴bullデータモデルによる分類bullMongoDBCassandraVoltDBの実演
bullアーキテクチャによる分類(簡単に)bull主要な製品(7+1製品)の紹介bull活用事例例(Cloudian)の紹介
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
駆け足です
bull本当は2日くらいかけて学ぶ内容を3時間でやります
bullこのスライドの置き場所bullhttpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
bull推薦図書(4冊)も紹介します
4
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
河野 達也 Tatsuya Kawano
エバンジェリスト
開発者
著者の一人
5
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クラウディアン株式会社bull CloudianS3完全準拠オブジェクトストレージ
bull Hibari DB GBクラスのウェブメールに採用
bull NOSQL afternoon in Japanを主催(2010年年)bullグローバル開発リーダー Gary Ogasawarabull Inktomiで開発を経験(CAP定理理のE Brewer氏らが立立ち上げた会社)
6
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
本セミナー資料料のライセンス(使用条件)bull スライドクリエイティブコモンズ表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30)
bull 原著作者のクレジットを表示しbull かつ営利利目的で利利用しなければbull 本作品を複製頒布展示実演することができるbull 二次的著作物を作成することができる
bull ソースコード MITライセンス
7
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの特徴
スケーラビリティー半構造のデータ
8
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQL Not Only SQLbull ウィキペディア「NoSQL」のページよりbull NoSQL(一般に ldquoNot only SQLrdquo と解釈される)はリレーショナルデータベース管理理システム (RDBMS) 以外のデータベース管理理システムを指すおおまかな分類語
bull RDBをやみくもに使用してきた長い歴史を打破しそれ以外のデータベースの利利用発展を促進させようとする運動の標語となっている
bull このようなデータベースの傾向として以下が挙げられるbull 固定されたスキーマに縛られないbull 関係モデルの結合操作を利利用しないこと(場合によっては単にそのような機能が欠落落しているだけ)
bull 水平スケーラビリティが確保しやすい事が多いことbull トランザクションを利利用できないものが多いこと
9
httpjawikipediaorgwikiNoSQL
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
httpwwwslidesharenetsunsuk7tphbase-at-line
10
なぜ NOSQL なのか
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License2
本日の内容
bullNOSQLの特徴bullデータモデルによる分類bullMongoDBCassandraVoltDBの実演
bullアーキテクチャによる分類(簡単に)bull主要な製品(7+1製品)の紹介bull活用事例例(Cloudian)の紹介
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
駆け足です
bull本当は2日くらいかけて学ぶ内容を3時間でやります
bullこのスライドの置き場所bullhttpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
bull推薦図書(4冊)も紹介します
4
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
河野 達也 Tatsuya Kawano
エバンジェリスト
開発者
著者の一人
5
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クラウディアン株式会社bull CloudianS3完全準拠オブジェクトストレージ
bull Hibari DB GBクラスのウェブメールに採用
bull NOSQL afternoon in Japanを主催(2010年年)bullグローバル開発リーダー Gary Ogasawarabull Inktomiで開発を経験(CAP定理理のE Brewer氏らが立立ち上げた会社)
6
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
本セミナー資料料のライセンス(使用条件)bull スライドクリエイティブコモンズ表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30)
bull 原著作者のクレジットを表示しbull かつ営利利目的で利利用しなければbull 本作品を複製頒布展示実演することができるbull 二次的著作物を作成することができる
bull ソースコード MITライセンス
7
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの特徴
スケーラビリティー半構造のデータ
8
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQL Not Only SQLbull ウィキペディア「NoSQL」のページよりbull NoSQL(一般に ldquoNot only SQLrdquo と解釈される)はリレーショナルデータベース管理理システム (RDBMS) 以外のデータベース管理理システムを指すおおまかな分類語
bull RDBをやみくもに使用してきた長い歴史を打破しそれ以外のデータベースの利利用発展を促進させようとする運動の標語となっている
bull このようなデータベースの傾向として以下が挙げられるbull 固定されたスキーマに縛られないbull 関係モデルの結合操作を利利用しないこと(場合によっては単にそのような機能が欠落落しているだけ)
bull 水平スケーラビリティが確保しやすい事が多いことbull トランザクションを利利用できないものが多いこと
9
httpjawikipediaorgwikiNoSQL
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
httpwwwslidesharenetsunsuk7tphbase-at-line
10
なぜ NOSQL なのか
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
駆け足です
bull本当は2日くらいかけて学ぶ内容を3時間でやります
bullこのスライドの置き場所bullhttpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
bull推薦図書(4冊)も紹介します
4
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
河野 達也 Tatsuya Kawano
エバンジェリスト
開発者
著者の一人
5
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クラウディアン株式会社bull CloudianS3完全準拠オブジェクトストレージ
bull Hibari DB GBクラスのウェブメールに採用
bull NOSQL afternoon in Japanを主催(2010年年)bullグローバル開発リーダー Gary Ogasawarabull Inktomiで開発を経験(CAP定理理のE Brewer氏らが立立ち上げた会社)
6
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
本セミナー資料料のライセンス(使用条件)bull スライドクリエイティブコモンズ表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30)
bull 原著作者のクレジットを表示しbull かつ営利利目的で利利用しなければbull 本作品を複製頒布展示実演することができるbull 二次的著作物を作成することができる
bull ソースコード MITライセンス
7
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの特徴
スケーラビリティー半構造のデータ
8
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQL Not Only SQLbull ウィキペディア「NoSQL」のページよりbull NoSQL(一般に ldquoNot only SQLrdquo と解釈される)はリレーショナルデータベース管理理システム (RDBMS) 以外のデータベース管理理システムを指すおおまかな分類語
bull RDBをやみくもに使用してきた長い歴史を打破しそれ以外のデータベースの利利用発展を促進させようとする運動の標語となっている
bull このようなデータベースの傾向として以下が挙げられるbull 固定されたスキーマに縛られないbull 関係モデルの結合操作を利利用しないこと(場合によっては単にそのような機能が欠落落しているだけ)
bull 水平スケーラビリティが確保しやすい事が多いことbull トランザクションを利利用できないものが多いこと
9
httpjawikipediaorgwikiNoSQL
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
httpwwwslidesharenetsunsuk7tphbase-at-line
10
なぜ NOSQL なのか
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
駆け足です
bull本当は2日くらいかけて学ぶ内容を3時間でやります
bullこのスライドの置き場所bullhttpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
bull推薦図書(4冊)も紹介します
4
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
河野 達也 Tatsuya Kawano
エバンジェリスト
開発者
著者の一人
5
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クラウディアン株式会社bull CloudianS3完全準拠オブジェクトストレージ
bull Hibari DB GBクラスのウェブメールに採用
bull NOSQL afternoon in Japanを主催(2010年年)bullグローバル開発リーダー Gary Ogasawarabull Inktomiで開発を経験(CAP定理理のE Brewer氏らが立立ち上げた会社)
6
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
本セミナー資料料のライセンス(使用条件)bull スライドクリエイティブコモンズ表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30)
bull 原著作者のクレジットを表示しbull かつ営利利目的で利利用しなければbull 本作品を複製頒布展示実演することができるbull 二次的著作物を作成することができる
bull ソースコード MITライセンス
7
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの特徴
スケーラビリティー半構造のデータ
8
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQL Not Only SQLbull ウィキペディア「NoSQL」のページよりbull NoSQL(一般に ldquoNot only SQLrdquo と解釈される)はリレーショナルデータベース管理理システム (RDBMS) 以外のデータベース管理理システムを指すおおまかな分類語
bull RDBをやみくもに使用してきた長い歴史を打破しそれ以外のデータベースの利利用発展を促進させようとする運動の標語となっている
bull このようなデータベースの傾向として以下が挙げられるbull 固定されたスキーマに縛られないbull 関係モデルの結合操作を利利用しないこと(場合によっては単にそのような機能が欠落落しているだけ)
bull 水平スケーラビリティが確保しやすい事が多いことbull トランザクションを利利用できないものが多いこと
9
httpjawikipediaorgwikiNoSQL
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
httpwwwslidesharenetsunsuk7tphbase-at-line
10
なぜ NOSQL なのか
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
河野 達也 Tatsuya Kawano
エバンジェリスト
開発者
著者の一人
5
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クラウディアン株式会社bull CloudianS3完全準拠オブジェクトストレージ
bull Hibari DB GBクラスのウェブメールに採用
bull NOSQL afternoon in Japanを主催(2010年年)bullグローバル開発リーダー Gary Ogasawarabull Inktomiで開発を経験(CAP定理理のE Brewer氏らが立立ち上げた会社)
6
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
本セミナー資料料のライセンス(使用条件)bull スライドクリエイティブコモンズ表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30)
bull 原著作者のクレジットを表示しbull かつ営利利目的で利利用しなければbull 本作品を複製頒布展示実演することができるbull 二次的著作物を作成することができる
bull ソースコード MITライセンス
7
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの特徴
スケーラビリティー半構造のデータ
8
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQL Not Only SQLbull ウィキペディア「NoSQL」のページよりbull NoSQL(一般に ldquoNot only SQLrdquo と解釈される)はリレーショナルデータベース管理理システム (RDBMS) 以外のデータベース管理理システムを指すおおまかな分類語
bull RDBをやみくもに使用してきた長い歴史を打破しそれ以外のデータベースの利利用発展を促進させようとする運動の標語となっている
bull このようなデータベースの傾向として以下が挙げられるbull 固定されたスキーマに縛られないbull 関係モデルの結合操作を利利用しないこと(場合によっては単にそのような機能が欠落落しているだけ)
bull 水平スケーラビリティが確保しやすい事が多いことbull トランザクションを利利用できないものが多いこと
9
httpjawikipediaorgwikiNoSQL
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
httpwwwslidesharenetsunsuk7tphbase-at-line
10
なぜ NOSQL なのか
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クラウディアン株式会社bull CloudianS3完全準拠オブジェクトストレージ
bull Hibari DB GBクラスのウェブメールに採用
bull NOSQL afternoon in Japanを主催(2010年年)bullグローバル開発リーダー Gary Ogasawarabull Inktomiで開発を経験(CAP定理理のE Brewer氏らが立立ち上げた会社)
6
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
本セミナー資料料のライセンス(使用条件)bull スライドクリエイティブコモンズ表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30)
bull 原著作者のクレジットを表示しbull かつ営利利目的で利利用しなければbull 本作品を複製頒布展示実演することができるbull 二次的著作物を作成することができる
bull ソースコード MITライセンス
7
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの特徴
スケーラビリティー半構造のデータ
8
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQL Not Only SQLbull ウィキペディア「NoSQL」のページよりbull NoSQL(一般に ldquoNot only SQLrdquo と解釈される)はリレーショナルデータベース管理理システム (RDBMS) 以外のデータベース管理理システムを指すおおまかな分類語
bull RDBをやみくもに使用してきた長い歴史を打破しそれ以外のデータベースの利利用発展を促進させようとする運動の標語となっている
bull このようなデータベースの傾向として以下が挙げられるbull 固定されたスキーマに縛られないbull 関係モデルの結合操作を利利用しないこと(場合によっては単にそのような機能が欠落落しているだけ)
bull 水平スケーラビリティが確保しやすい事が多いことbull トランザクションを利利用できないものが多いこと
9
httpjawikipediaorgwikiNoSQL
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
httpwwwslidesharenetsunsuk7tphbase-at-line
10
なぜ NOSQL なのか
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
本セミナー資料料のライセンス(使用条件)bull スライドクリエイティブコモンズ表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30)
bull 原著作者のクレジットを表示しbull かつ営利利目的で利利用しなければbull 本作品を複製頒布展示実演することができるbull 二次的著作物を作成することができる
bull ソースコード MITライセンス
7
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの特徴
スケーラビリティー半構造のデータ
8
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQL Not Only SQLbull ウィキペディア「NoSQL」のページよりbull NoSQL(一般に ldquoNot only SQLrdquo と解釈される)はリレーショナルデータベース管理理システム (RDBMS) 以外のデータベース管理理システムを指すおおまかな分類語
bull RDBをやみくもに使用してきた長い歴史を打破しそれ以外のデータベースの利利用発展を促進させようとする運動の標語となっている
bull このようなデータベースの傾向として以下が挙げられるbull 固定されたスキーマに縛られないbull 関係モデルの結合操作を利利用しないこと(場合によっては単にそのような機能が欠落落しているだけ)
bull 水平スケーラビリティが確保しやすい事が多いことbull トランザクションを利利用できないものが多いこと
9
httpjawikipediaorgwikiNoSQL
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
httpwwwslidesharenetsunsuk7tphbase-at-line
10
なぜ NOSQL なのか
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの特徴
スケーラビリティー半構造のデータ
8
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQL Not Only SQLbull ウィキペディア「NoSQL」のページよりbull NoSQL(一般に ldquoNot only SQLrdquo と解釈される)はリレーショナルデータベース管理理システム (RDBMS) 以外のデータベース管理理システムを指すおおまかな分類語
bull RDBをやみくもに使用してきた長い歴史を打破しそれ以外のデータベースの利利用発展を促進させようとする運動の標語となっている
bull このようなデータベースの傾向として以下が挙げられるbull 固定されたスキーマに縛られないbull 関係モデルの結合操作を利利用しないこと(場合によっては単にそのような機能が欠落落しているだけ)
bull 水平スケーラビリティが確保しやすい事が多いことbull トランザクションを利利用できないものが多いこと
9
httpjawikipediaorgwikiNoSQL
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
httpwwwslidesharenetsunsuk7tphbase-at-line
10
なぜ NOSQL なのか
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQL Not Only SQLbull ウィキペディア「NoSQL」のページよりbull NoSQL(一般に ldquoNot only SQLrdquo と解釈される)はリレーショナルデータベース管理理システム (RDBMS) 以外のデータベース管理理システムを指すおおまかな分類語
bull RDBをやみくもに使用してきた長い歴史を打破しそれ以外のデータベースの利利用発展を促進させようとする運動の標語となっている
bull このようなデータベースの傾向として以下が挙げられるbull 固定されたスキーマに縛られないbull 関係モデルの結合操作を利利用しないこと(場合によっては単にそのような機能が欠落落しているだけ)
bull 水平スケーラビリティが確保しやすい事が多いことbull トランザクションを利利用できないものが多いこと
9
httpjawikipediaorgwikiNoSQL
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
httpwwwslidesharenetsunsuk7tphbase-at-line
10
なぜ NOSQL なのか
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
httpwwwslidesharenetsunsuk7tphbase-at-line
10
なぜ NOSQL なのか
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
M2Memsp センサーデータ
0 1 7
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
含まれるからです 例えばスマートグリッドは家庭に設置されたスマートメーターが電力消費のログ(記録)を24時間送り続けそのログ情報を保存分析して電力供給を常に最適化する仕組みです東日本大震災以降は各家庭の太陽光発電や地域内で自家発電した電力を融通しあう際の制御や管理のために高度なITシステムの構築が進められていると聞きます24時間365日休止しない機械対機械の通信記録となれば大量のデータになるのは当然です M2MやSNSはほんの一例に過ぎません過去には存在しなかったデータがあらゆるビジネスや業界で生じ始めることは容易に想像できますし日本に限らず世界が ITを駆使する社会へ突き進んでいます言うまでもなくそのような社会では誰もがビッグデータと向き合うことになります
図0-3 経済産業省「スマートメーター制度研究会報告書」より抜粋
P011-019_序章(0章)_責indd 017P011-019_序章(0章)_責indd 017 20120406 10502720120406 105027
11
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
従来のリレーショナルDBでは対応が難しい
bull膨大な量量bull12TB日bull速く処理理するbull12TB divide 80MB秒 ≒ 42時間bull半構造データbull全てのデータを均一に整えるのは難しい
12
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ビッグデータに対応するための新技術
0 1 5
0序章
ビッグデータの時代
01 ビッグデータとNOSQLの登場
を中心としたWebサービスがインターネットの主役となっています伝統的なITの成果はそうしたサービスのプロバイダたちが気軽にかつすぐに利用できる技術ではなさそうです これに対し早い時期からビッグデータに直面し自ら対応技術を開発してきたのがGoogleやAmazonですWebサービスを事業とするこれらのインターネット企業群はサーバー等のハードウェアコストが大量生産により年々ドラスティックに低減しつつ集積技術の進化とともにハードディスクの容量やメモリの速度が年々向上していく事実に目をつけましたそうしたハードウェアを何百台何千台と並べそこへビッグデータを分散して格納するソフトウェアを自社で開発しましたGoogleのBigtable(ビッグテーブル)やAmazonのDynamo(ダイナモ)がそれです BigtableやDynamoの論文発表が契機となりソフトウェアによる大規模分散技術は俄かに脚光を浴びましたビッグデータに直面していたWebサービスのエンジニア達がこれに触発されBigtableやDynamoの
図0-2 Google BigtableとAmazon Dynamoの発表論文(表紙の一部)
P011-019_序章(0章)_責indd 015P011-019_序章(0章)_責indd 015 20120406 10502620120406 105026
13
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大手Webサービスが利利用を開始
0 2 4
をNOSQLに切り替え始めたという事実がこのムーブメントを大きく後押ししています Googleが発表したBigtableの論文は他の多くのNOSQLに影響を与えましたその論文の中で同社は「WebインデックスGoogleアナリティクスGoogle EarthGoogleファイナンスOrkutPersonalized SearchWritelyをはじめ60以上のサービスにBigtableを利用している」ことを明らかにしました Amazonの発表論文では「DynamoはAmazonのショッピングカートのために開発された」としています BigtableとDynamoの影響を受けているCassandraはFacebookにおいてメッセージを保存しているIn-Boxサーチのために開発されオープンソースとしてリリースされましたその後Cassandraは大規模なニュース関連SNSであるDigg(ディッグ)やクラウドサービスの大手
図1-2 代表的なNOSQLの利用企業の例
P021-044_第1章_責indd 024P021-044_第1章_責indd 024 20120406 10540620120406 105406
14
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
SQL以外のデータベースを総称
bullNOSQLは世界に100種類以上bull ldquoOne size does not fit allrdquobull知名度度だけで選ぶと大失敗するbull用途に合った製品を選ぶためにはNOSQLに使われる技術を理理解し個々の製品の特徴を把握する必要がある
15
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴
bull スケールアウト性(水平スケーラビリティー)に優れるものが多いbull 汎用的で価格のこなれたハードウェアを多数並べることで処理理能力力データの格納容量量故障への耐性などを高める
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
0 5 7
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
すぐに一杯になってしまいますその場合ハードディスクをより大きなものに置換することがひとつの対策となりますつまりハードウェアのスケールをアップしていくのですそうしてデータを全て移し替えまた一杯になったらさらに大きなハードディスクに置換するというサイクルを繰り返しますこうした対策方法を「スケールアップ」と呼びます(図2-6)
もうひとつの対策は新たにサーバーを追加し各サーバーにデータを分割して保存するという方法ですデータが増えた場合サーバーを次々と追加することでデータの保存容量を拡張していくというものですこの方法を「スケールアウト」と呼んでいます(図2-7)NOSQLの基本的な考え方はスケールアップではなくこちらの方です
図2-6 スケールアップのイメージ
スケールアップ
スケールアウト
図2-7 スケールアウトのイメージ
P045-072_第2章_責indd 057P045-072_第2章_責indd 057 20120406 10593520120406 105935
16
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
一般的なNOSQL製品の特徴(続き)
bull固定されたスキーマに縛られないbull複雑で多様に変化するデータ構造に対応bull高可用性と高信頼性bull耐障害性bullサービス無停止でノード追加
17
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLは用途を絞り込んだデータベース
bull機能が少ないbullリレーショナルモデルの結合操作ができないbullトランザクションが使えないものが多いbull逆にある用途のために機能を特化強化したものもある(例例グラフ型NOSQL)
bullデータの整合性が緩い(結果整合性など)bull製品の成熟度度bull主要な製品は成熟期にさしかかりつつある
18
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データモデルによる分類
キーバリュー型ドキュメント指向型カラムファミリー型グラフ型
httpbeautifuldatanet201201telling-stories-with-network-data-instagram-in-china
19
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLのデータモデル
httpwwwneo4jorglearnnosql
20
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
リレーショナルDB(RDB)のデータモデル
bull行行と列列で構成されるテーブルを定義bullテーブル間の関係性を定義bull正規化により冗長生と不不整合を排除
0 5 0
NOSQLを高い視点から理解するため共通する要素に着目してNOSQLデータベースを大きく分類しそれぞれの特徴を説明したいと思います一般的によく用いられる分類方法はデータモデル(データ構造)による分類ですそれぞれの特徴を明らかにするためにまずはSQLデータベース(RDB)のデータモデルからおさらいしておきましょう
SQLのデータモデル
RDBでは行と列で構成されるテーブル(表)の形でデータ構造の設計をしそのうえでテーブル間の関係性を定義します図にすると図2-1
図2-1 RDBのデータモデルのイメージ
2222NOSQ Lをデータモデルから分類する
Basic Knowledge of NOSQL
P045-072_第2章_責indd 050P045-072_第2章_責indd 050 20120406 10593220120406 105932
21
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
RDBにおけるデータ分散
分散環境では性能がスケールしずらい
0 5 8
キーバリュー型のデータモデルの利点はRDBよりも遥かに簡単にスケールアウトが行えることにありますRDBの場合にはデータ間の関係性が厳密に定義されるので一つのテーブルの列定義を変更している最中に何らかの読み書きが発生した場合に他のテーブルとの整合性を保つための排他制御が必要になりますまた 定義変更中の待ち受け処理などを別に追加しなければならないケースもあります大規模に分散された複数のサーバーがネットワークを介してそれぞれのデータの関係性を維持させるのが簡単でないことは容易に想像できると思います(図2-8)
一方キーを指定するだけでバリューを探し出せるキーバリュー型であればスケールアウトにより数十台数百台にサーバーが増えても複数のサーバーにデータを容易に分割することできますキーの管理を担当するサーバーやスマートクライアント(キーの管理も行うクライアント)がどこにキーがあるかを把握していればよいからです(図2-9)
図2-8 RDBにおけるデータ分割のイメージ
サーバー 1 サーバー 2
サーバー 3 サーバー 4
P045-072_第2章_責indd 058P045-072_第2章_責indd 058 20120406 10594520120406 105945
22
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型
bull辞書のようなデータ形式
0 5 2
の「対」が「行」です新しいデータが追加されるごとに行が加えられていきますデータが増えるに従って表が縦の方向に伸びていくイメージです キーバリュー型に該当するNOSQLデータベースにはDynamoVoldemortRiakHibariRedisScalaris(スカラリス)Tokyo Cabi-netTyrant等があります
カラム指向型のデータモデル
とてもシンプルなキーバリュー型を少し高度にしたデータモデルがGoogleのBigtableが採用したカラム指向型ですこのカラム指向型はキーが1つのバリューと対になるのではなく行に対して付されたキー(行キー)が複数のカラム(列)を持つことができます また行キーごとの列の数(カラム数)はRDBのテーブルのように静的固定ではなく動的に追加していくこともできますまたキーバリュー型と異なりある行キーの全てのカラムにバリューが挿入されていないことも許容しますこのカラム指向型は図2-3のように行だけではなく列方向つまり縦方向と横方向に伸ばしていくことができるデータモデルです
図2-2 キーバリュー型データモデルのイメージ
P045-072_第2章_責indd 052P045-072_第2章_責indd 052 20120406 10593320120406 105933
23
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータ分散
テーブル間のリレーションやトランザクションがないため容易易にスケールする
0 5 9
2第2章
NOSQLのデータモデル
23 キーバリュー型の特徴
複数のサーバーに複数のバリューを複製する
キーバリュー型においてこのデータ分割を行う際最も簡単な方法が「シャーディング(Sharding)」ですキーAはサーバーXキー BはサーバーYというようにデータを分割して格納することを指します しかしこのような形にデータを格納すると例えばサーバーXがダウンしたらキーAとそのバリューの両方を失うことになりますそのため大規模に分散する並列システムではクラスタの中でキーとバリューの対を複製しそれを複数のサーバーに保存しておく必要があります(図2-10) ところでキーは単なる識別子のようなものですからキーを見ただけではそのキーに紐づくバリューが更新されているかどうかはわかりませんその前提の上で複数のサーバーに複数のバリューが複製されたらどうなるでしょうかあるサーバーのバリューが更新されるとシステム内に複数のバージョンが存在してしまう心配が生じます
サーバー 1 サーバー 2
サーバー 3 サーバー 4
図2-9 キーバリュー型におけるデータ分割のイメージ
P045-072_第2章_責indd 059P045-072_第2章_責indd 059 20120406 10594520120406 105945
24
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
キーバリュー型におけるデータの複製
0 6 0
このような課題に対するソリューションを実装しておらず単独のサーバーで運用することを前提としたNOSQLデータベースもたくさんありますその一方でBigtableやDynamoに触発された大規模分散型NOSQLデータベースの多くは複数のノードにデータを分散配置した際の課題を解決する技術や概念を実装していますそれらの技術は第3章で紹介します
サーバー 1 サーバー 2
サーバー 3
複製複製
複製
図2-10 キーバリュー型におけるデータの複製
P045-072_第2章_責indd 060P045-072_第2章_責indd 060 20120406 10594620120406 105946
25
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ドキュメント指向型
bullバリューに構造を持ったデータを格納bull各項目にインデックスを付けられる
author joe created new Date(03282009) title Yet another blog post text Here is the text tags [ example joe ] comments [ author jim comment I disagree author nancy comment Good post ]
26
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型
27
httpwwwdatastaxcomdocs11ddlcolumn_family
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
カラムファミリー型(続き)
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 10594728
0 6 3
2第2章
NOSQLのデータモデル
24 カラム指向型の特徴
でカラムの名前が固定ではないことに注意してください このタイムスタンプの例のようにカラム指向型では行キーに連なるカラムの名前を時間とともに変化する性質のものとすることができますそしてRDB等との決定的な違いとしてカラムの数を後から増やすことができますRDBの行(レコード)のようにデータの発生に応じて動的にかつほぼ無限にカラムを追加していくことが可能なのです
このSNSがサービスを開始するとランダムにツィートが登録されますそれを管理するためにツィートIDを行キーとする「ツィートカラムファミリー」を定義しますその中でツィートIDは図2-14のように新しいツィートが発生するごとに行として縦方向に追加されていきます
このデータベースにおいてユーザーのツィートを取得するにはユーザーラインカラムファミリーからユーザーのツィートIDを取得し各
図2-14 カラム指向型における行の追加ツィートカラムファミリー
行キー
キー(ツィートID)
新しいツィートごとに新しい行を加える
t342
タイムスタンプ
1234567
ボディ
NOSQL is fun
ユーザーネーム
gemini
ユーザー ID
u2415
カラム
図2-13 カラムの名前を固定しなくてよいユーザーラインカラムファミリー
行キー タイムスタンプ
ツィート ID
キー(ユーザーID)
新しいツィートごとに新しい行を加える
1234569
t389
1234568
t353
1234567
t342u2415
カラム
P045-072_第2章_責indd 063P045-072_第2章_責indd 063 20120406 10594720120406 105947
新しいツィート毎に新しい列列を加える
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
グラフ型
29
httpwwwneo4jorglearntry
bull グラフ構造の扱いに特化
bull データ同士の繋がりを可視化独自のクエリ言語で分析
bull 最短経路路の検索索
bull ソーシャルグラフジオメトリックグラフとリコメンド計算
bull データ構造上スケールアウトは困難
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoドキュメント指向型NOSQL
30
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullMongoDB を用いてドキュメント指向型NOSQLのデータモデルとクエリを確認します
bull比較のためにインメモリ型リレーショナルDBMSの VoltDB も紹介します
31
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013mongodb-‐‑‒ruby
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモの流流れ
bullリレーショナルDBMS(VoltDB)でMovieLensのデータ構造を確認
bullVoltDBでSQLを使ったクエリ
bullMongoDBでデータ構造とその柔軟性を確認
bullMongoDBでSQLと同等のクエリを実行行32
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
bullドキュメント内のフィールドはドキュメント毎に自由に持てるデータ構造に対する柔軟性が高い
bullMongoDBでは様々なクエリがサポートされている集計はMap Reduceで行行う
33
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)bull MongoDBだけで十分bull 大半の用途に十分な性能を持つbull 以下のようなケースではカラムファミリー型やキーバリュー型も検討する
bull さらに大規模なデータを扱いたいbull さらに低いレイテンシーまたは高いスループットが求められる
bull ACIDなトランザクションは実現できないbull リレーショナルモデルが最適な用途ならVoltDBのようなNewSQLも選択肢に
34
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
bullVoltDB は NewSQL と呼ばれNOSQLに匹敵するスケーラビリティーを持ちながらリレーショナルモデルとACIDなトランザクションを提供する
bull一方で柔軟性やエラスティック性(弾力力性)を犠牲にしている
bullサービス中のスキーマ変更更ができないbullサービス中のノード追加に制限がある
35
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
アーキテクチャによる分類
データ分割CAP定理理
36
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp コンシステントハッシング
0 9 4
システントハッシングでは入力データとなるキーの値としてこのハッシュ値を得ることによってキーの値が特定の値に偏ることなく広く均等に拡散するようにします そしてその整理番号に従ってリングの各スペースにキーを割り当てますキーが割り当てられたスペースを時計回りで進みそこで最初に配置されているノードにデータを書き込むというルールのアルゴリズムです
図3-13ではハッシュ値を00から10の間で設定しています4つのノードがリング状に配置されノードAには00ノードBには025ノードCには05ノードDには075という値が割り当てられていますもしキーの値(ハッシュ関数の演算結果)が02だった場合ノードAの00とノードBの025の間にキーのハッシュ値があるので時計回りで進んだ最初のノードBにデータを書き込むよう割り当てが行われますそして3つの複製を行うと設定していた場合には隣のノードCその隣のノードDという順番でデータが時計回りに複製されていきます
図3-13 コンシステントハッシングの概念図
00
05
グレーのノードにデータの複製を割り当て
ノードA
ノードC
ノードD
ノードB075 025
キーのハッシュ値
020
データ複製データ複製
P073-117_第3章_責indd 094P073-117_第3章_責indd 094 20120406 11063720120406 110637
0 9 6
図3-15 コンシステントハッシングにおけるノードの縮退
00
ノードCが取り除かれた場合
ノードA
ノードD
ノードB075 025
キーのハッシュ値
045
図3-16 コンシステントハッシングにおける負荷割り当ての調整
00
ノードCにデータの割り当てを増やす
ノードA
ノードD
ノードB075
ノードC
070
025
P073-117_第3章_責indd 096P073-117_第3章_責indd 096 20120406 11063820120406 110638
37
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ分割emsp シャーディング
1 0 0
bull タブレットサーバーの追加と削除を検知する bull タブレットサーバー間の負荷をバランスさせる bull ガベージコレクション3(ゴミ処理)を行うSS Tableと呼ばれるデータファイルのコンパクションを行う(コンパクションについては後述)
bull スキーマ変更を行う
タブレットサーバーは複数あり動的に追加と削除が可能で以下の役割を担います bull サーバーごとに10個から1000個のタブレットを格納する bull タブレットに対する書き込みと読み出しを司る bull 大きくなりすぎたタブレットを1つあたり100~ 200MBのサイズに分割する
図3-19のようにBigtableでは辞書配列に従ってキーの値がソートさ
図3-19 Bigtableのデータ割当てタブレット(リージョン)
行キー[ldquoArkansasrdquoldquoCaliforniardquo)
行キー[ldquoCaliforniardquoldquoCalifornia-LosAngelesrdquo)
行キー[ldquoCalifornia-LosAngelesrdquoldquoColoradordquo)
行キー[ldquoColoradordquoldquoFloridardquo)
タブレット(リージョン)サーバー 1
タブレット(リージョン)サーバー 2
3 ガベージコレクション(Garbage CollectionGC)とはプログラムが実行の際に確保したメモリ領域のうち不要になった領域を解放する処理です同様にハードディスク上で不要になった領域を削除する処理もこのように呼ばれますいずれの場合においてもその都度解放や削除を行うよりもある程度不要な領域が溜まった時に一括して行うことで全般的な性能を稼ぐのがこの仕組みの目的です
P073-117_第3章_責indd 100P073-117_第3章_責indd 100 20120406 11064120120406 110641
38
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Eric BrewerのCAP定理理
bull 注意bull C or Aはクエリの都度度調整可能
bull 証明されておらず厳密には定理理ではない
0 8 1
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ACM(Association for Computing Machinery)が主催したPODC(Prin-ciple Of Distributed Computing)シンポジウムにおける「Towards Ro-bust Distributed Systems」と題した基調講演の中でのことでした
ACIDとBASE
このプレゼンテーションにおいてEric Brewer氏はCAP定理を説明するためにACID(AtomicityConsistencyIsolationDurability)とBASE(Basically AvailableSoft-stateEventual Consistency)という2つの異なるデータベース特性について述べました
ACIDとはデータベースの特性のうちトランザクションが信頼性をもって実行されるための必要条件を定義したものですここで言うトランザクションとは相互依存のある複数の操作が「全ての処理を完了する」かまたは「完了せずに処理以前の状態に復元する」かのいずれかで終了
図3-6 Eric BrewerのCAP定理
「分散システムにおいてはこれら 3つのうち最大 2つしか満たすことができない」(2000 年 7月 19日 PODC基調講演)
Availability可用性
Consistency整合性
Partitions分断耐性
Tolerance to network
1 httpwwwcsberkeleyedu~brewercs262b-2004PODC-keynotepdfを参照
P073-117_第3章_責indd 081P073-117_第3章_責indd 081 20120406 11063120120406 110631
39
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
データ複製時の整合性
0 8 6
① クライアント1がAに対して更新要求を出しAは自身の持つデータを更新する
② Aはデータが更新されたことをBに伝えBは自身の持つデータ(の複製)を更新する
③ クライアント2がBに対して参照要求を出しクライアント1が更新したデータを取得する
この手順が無事に守られている限りAとBの整合性(C)もクライアント1と2の可用性(A)も維持されます DBMS側の動作でポイントとなるのは②つまりAとBが連動し相互のデータを同期させていることですもしネットワーク障害や一方のサーバーダウンによってAとBの間が分断されてしまったらどうなるでしょうか図3-9の左側を見てくださいAはBに更新を伝えることができずクライアント2は更新前の古いデータを読み出してしまうかも
図3-8 CAP定理のCPとAPにおける通常のケース
クライアント 1 クライアント 2
通常のケース(1)クライアントはデータの更新要求をAまたは Bのいずれか 一方に送る(2)Aと Bはデータが更新されたことを他方に通知する(3)通知を受けた側は自分のデータにその更新を反映する
レプリケーション(複製)
リクエスト
BA
データデータ
P073-117_第3章_責indd 086P073-117_第3章_責indd 086 20120406 11063320120406 110633
40
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
分割耐性
bullネットワークが分断されてもその特性(CPまたはAP)を維持する
41
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CPとAPemsp ネットワーク分割が発生
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
0 8 7
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
しれません そうなったときDBMSがどのように動いた方が好都合であるかというのがCPとAPの分かれ道です分断に際して整合性の維持を優先したければAかBの一方が停止すべきです仮にBが停止するとクライアント2は要求を実現できません「それでは困る」というのであればABとも稼働を続ける代わりにAとBの間にデータの不整合が生じますどちらを選ぶべきかはアプリケーションや業務上の要求条件次第です
図3-9 CAP定理のCPとAPにおいて分断が生じた場合
A B
クライアント1 クライアント2
Aと Bが分断されるとAはデータが更新されたことをBに伝えることができない
A B
クライアント2クライアント1
クライアント2クライアント1
CP(整合性と分断耐性)の場合リクエストは片方のグループ(仮にA)だけが受け付け他のグループは自主的に停止する
A B
AP(可用性と分断耐性)の場合リクエストは全てのグループが受け付けるがAと Bのデータは不整合となる
データデータ
クライアントが書き込みリクエストを送る
P073-117_第3章_責indd 087P073-117_第3章_責indd 087 20120406 11063420120406 110634
42
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ
0 8 8
整合性と性能のトレードオフ
ここまでNOSQLにおけるデータの整合性を巡りCAP定理ACIDBASEについて説明してきましたしかしこうした理論的に割り切った法則というものはどうしても学究的な色彩を拭えませんなぜなら整合性は調節することができるからです それを説明するためにDynamoの論文に触発されたCassandraVoldemortRiak等のNOSQLに実装されているQuorum(クォーラム)という基本概念を紹介します Quorumを直訳すると「(議決に必要な)定足数」という意味です分散型のデータベースシステムでは複製の整合性を保証するために用いたりネットワーク分断の際に継続して稼働するグループの選出に用いたりしますここではQuorumによる複製の整合性の保証について説明しましょう以下のような形で表されます R+W>Nの場合には整合性が保証できる
図3-10 Quorumの概念図[R+W<N]
書き込み(W=1) 読み出し(R=1)
R+W<Nの場合
複製(N=3)
書き込みが 1つのノードに行われているがノード123 のどのノードから 1つだけデータを読み出すかはわからない
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 088P073-117_第3章_責indd 088 20120406 11063420120406 110634
43
bull結果整合性(Eventual Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
整合性と性能のトレードオフ(続き)
0 8 9
3第3章
アーキテクチャの
基本概念と技術
32 データの整合性に関する概念と技術
ここでNは「複製(レプリカ)の数」Rは「ノードから読み出す数」Wは「ノードに書き込む数」です
具体的な数を入れて説明しましょう分散型システム内に作る複製(レプリカ)の数Nを3とします1つのノードにデータが書き込まれた段階で書き込み完了の応答をクライアントに返すとしますつまりWは1ですそのデータを読み出す数Rを1としますこの場合R+Wは1+1の2となりNの3よりも小さいのでR+W<Nとなります これは結果的には3つ複製を作るのですが1つのノードへの書き込みが完了した時点で読み出しが可能な状態となっていますそうなると読み出すノードが1つですので必ずしも書き込み完了が確認されたノードから読み出される保証はありません しかしNを3のままWを2Rを2とすれば2つのノードに書き込まれその書き込みが完了した時点で2つのノードから読み出すので最低でも1つは書き込み完了が確認されたノードから読み出すことになり結果的にデータの整合性を保証できることになります
図3-11 Quorumの概念図[R+W>N]
書き込み(W=2) 読み出し(R=2)
R+W>Nの場合
複製(N=3)
書き込みが 2つのノードに行われ読み出しが 2つのノードに行われれば必ず書き込みが行われた 2つのノードのうちの 1つに行きつく
ノード 1 ノード 2 ノード 3
P073-117_第3章_責indd 089P073-117_第3章_責indd 089 20120406 11063520120406 110635
44
bull強い整合性(Strong Consistency)
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
広域複製の課題
bullネットワークの遅延が大きい環境bullStrong Consistencyでは性能が大きく劣劣化bullEventual Consistencyではアプリケーションロジックが複雑になる
bullイベントの因果関係に着目した Causal Consistencyという手法もある
45
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistencybull Aさんが写真をアップロードbull Aさんが写真をアルバムに登録bull B君がAさんのアルバムを開く
bull Eventual Consistencyではビューに不不整合が発生するかもしれない
bull 写真がまだ登録されていないのに更更新されたアルバムが見見える
bull Causal Consistencyではこのようなことは避けられる46
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Causal Consistency
bullStrong Consistencyより緩く以下のようなことは実現できない
bullトランザクショナルな操作bullユニーク性などのintegrity制約bullCausal Consistencyは今後広域複製で注目されそうな手法
47
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Demoカラムファミリー型NOSQL
48
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
このデモでは
bullCassandra に MovieLens を格納します
bullCQL3のテーブル定義を確認bullCQL3でクエリbullmoviesカラムファミリーとratingsカラムファミリーの内部構成を確認
49
デモで使用するコードhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013cassandra-‐‑‒cql3
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
CQL3層での MovieLens データ構造
50
movie_id title genres
1
788
Toy Story Anime Comedy For-‐‑‒Children
Relative Fear Horror Thriller
movie_id user_id timestamp rating
1 1
1 2
788 1
788 4
5
3
3
3
movies テーブル
ratings テーブル
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cassandraストレージ層でのデータ構造
51
行行キー movies カラムファミリーmovies カラムファミリーmovies カラムファミリー ratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリーratings カラムファミリー
11
788788
title genresAnime 1 1timestamp 1rating 2 2timestamp 2rating
Toy Story 空欄 空 5 空 3
title genresHorror 1 1timestamp 1rating 4 4timestamp 4rating
Relative Fear 空欄 空 3 空 3
bull ratingsカラムファミリーは横(列列方向)に成長するbull このような数千数万の列列を持つ行行を「wide row」と呼ぶbull moviesとratingsはリレーショナルモデルで2つのテーブルを結合した時とそっくりの構造
bull このようにテーブルを結合した状態でデータを格納することをリレーショナルモデルでは非正規化と呼ぶ管理理はしづらくなるが性能を大きく改善できるテクニックのひとつ
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ
52
bullカラムファミリー型 NOSQL ではカラムを自由に追加できる性質を利利用してリレーショナルDBにおけるテーブルの非正規化と同じことを実現できる
bull非正規化により結合操作を代用できるだけでなくReadを高速化できる
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
デモのまとめ(続き)
53
bull CassandraではSQL風のクエリ言語とスキーマを導入しモデリングの難しさを排除しようとしているwide rowもCQL3で複合キーを持つテーブルを定義することで内部的に作成される
bull CQL3はスケーラビリティーを保つためにリレーショナルモデルの結合操作はサポートしない(代わりに wide rowつまり複合キーを持つテーブルやコレクション型を使う)
bull 一方でVoltDBでは柔軟性や弾力力性を犠牲にした
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
主な製品CassandraHBaseRiakMongoDBRedisInfinispanNeo4JVoltDB (NewSQL)
0 8 4
分散型のNOSQLはCPかAPのいずれか
CAP定理に基づいたNOSQLデータベースの分類がNathan Hurst氏のブログ「Visual Guide to NOSQL Systems」2で紹介されています
図3-7を見るとほぼ全てのNOSQLデータベースがCP(整合性と分断耐性)かAP(可用性と分断耐性)に分類されていることがわかると思いますこれはNOSQLデータベースが主にビッグデータを扱うことから多くの場合複数のノードで構成される分散システムとなることに起因していますまず必須条件として分断耐性(P)を備えそのうえで整合性
図3-7 CAP定理によるNOSQLの分類
可用性どのクライアントも常に読み出しと書き込みができる
整合性すべてのクライアントが常に同一のデータを見ている
分断耐性物理ネットワークが分断されても間違った結果を引き起こさない
CA APRDBMS(MySQLPostgres 等)Aster DataGreenplumVertica
DynamoVoldemortTokyo CabinetKAI
CassandraSimpleDBCouchDBRiak
CPBigtableHypertableHBase
MongoDBTerrastoreScalaris
Berkeley DBMemcache DBRedis
2 者選択
A
C P
データモデルリレーショナル型(比較対照)キーバリュー型カラム指向型テーブルドキュメント指向型
2 httpblognahurstcomvisual-guide-to-nosql-systemsを参照
P073-117_第3章_責indd 084P073-117_第3章_責indd 084 20120406 11063220120406 110632
54
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Apache Cassandra
bull Amazon DynamoとGoogle Bigtableを参考に設計された
bull カラムファミリー型bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く100台程度度のクラスターの運用実績が豊富Writeが高速なことが特徴
bull 最新のバージョンではCQL3というSQL風のクエリ言語を備える
55
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Google Bigtableを参考に設計bullカラムファミリー型bull強い整合性(CP)bull自動シャーディングを採用しスケールアウト性に優れる
bull大規模データに強く100台程度度のクラスターの運用実績が豊富 Hadoop環境と相性がよい
56
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull Amazon Dynamoを参考に設計bull キーバリュー型bull JSONの扱いに優れ使い勝手はドキュメント指向型に近い
bull 緩い整合性(調整可能APrarrCP)bull コンシステントハッシングを採用しスケールアウト性に優れる
bull 大規模データに強く 50台程度度のクラスターの運用実績が豊富 安定性が高く扱いやすいことが特徴
57
Basho Riak
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullドキュメント指向型bull強い整合性(CP)bull分散環境では 緩い整合性(AP)になるbullデータモデルの扱いやすさと強力力なクエリが特徴ウェブアプリ開発で特に人気が高い
bull分散構成では自動シャーディングとレプリケーションクラスターを組み合わせることになりリソースの使用効率率率が悪い
58
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull キーバリュー型bull リストやハッシュなどデータ構造をネイティブでサポート
bull 強い整合性(CP)bull インメモリ高速 bull リッチなデータ構造と高速性からランキング情報ユーザーのアクティビティ統計情報などのデータ格納先として人気がある
bull 高可用性構成に対応しているが現バージョンではスケールアウトはできない
59
Redis
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull JBoss Cacheから派生したデータグリッド製品bull JavaのキャッシュAPIに準拠bull キーバリュー型インメモリ高速bull Java以外のクライアントもサポートbull 強い整合性(CP)だが非同期操作などのスループットを高める仕組みが豊富
bull ACIDなトランザクションをサポートbull コンシステントハッシングを採用しスケールアウト性に優れるbull キャッシュローダーにより既存のデータストアとバックグラウンドでデーターを同期できる
bull RDBMSAmazon S3Cassandraなどに対応60
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 主な用途bull キャッシュとしてbull Hibernateの2次キャッシュbull JBoss AS(Application Server)のセッションキャッシュ
bull Luceneインデックスの格納bull データグリッドとしてbull 株式のトレーディングシステムbull ニアリアルタイムのデータ分析リスク計算
61
続き
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullグラフ型bullグラフエンジンのデファクトスタンダードbull深いグラフのトラバースではRDBMSの1000倍以上の性能を発揮
bullACIDなトランザクションをサポートbull専用のクエリ言語を持ちグラフの可視化ができる(対話型の分析ツールにもなる)
62
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bullオンライントランザクション処理理に特化したインメモリ型のリレーショナルデータベース
bullPostgres や Ingres などのデータベース開発を手がけた Michael Stonebraker氏が設計
bullNewSQLと呼ばれる bullSQLとACIDなトランザクションが使えるbull高速でスケールアウト性に優れる63
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
bull 柔軟性や弾力力性(エラスティック性)が犠牲にbull 事前にストアドプロシージャを書いてコンパイルするアドホックなクエリでは性能を発揮できない
bull 結合できるテーブル数に限りがあるbull 分析用途には不不向きRDBMSやHadoopなどへの差分データ連携機能を備える
bull サービス稼働中にスキーマの変更更はできないbull サービス稼働中のノード追加に制限があるbull 現状エンタープライズ版のみノード追加が可能さらに複製機能をオフにしたテーブルのみが対象となる
64
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
ApacheCassandra
BashoRiak
ApacheHBase MongoDB Redis Infinispan Neo4J VoltDB
バージョン
開発者括弧内はスポンサー
データモデル
メインストレージ
整合性モデル
ACID Transaction
サーバーサイドプロシージャ
SQL風クエリ
高可用性(HA)構成
スケールアウト性
エラスティック性
永続性
遠隔地へのデータ複製
12 13 094 24 26 53 19 34
ASF Basho Technologies
ASF 10gen S Sanfilippo+
(Pivotal)
JBoss+
(Red Hat)
Neo Technology
VoltDB
CF KV CF ドキュメント KV(データ構造) KV グラフ リレーショ
ナル
HDDSSD HDDSSD HDDSSD HDDSSD インメモリ インメモリ HDDSSD インメモリ
AP AP CP 非分散HACP分散HAAP CP CP CP CP
times times times times times
times JavaScript Java JavaScript Lua Java times Java
(CQL) times times times times times times
times times
times times times有償版は
非同期同期
times(有償版は)非同期
非同期
非同期
非同期
非同期
times 非同期
2013年年7月現在オープンソースソフトウェアの主なNOSQL製品
スケールアウト性ノードを増やすことで性能がリニアにスケールするかemsp エラスティック性サービス無停止でノードの追加停止できるか永続性停電などの全体障害でもデータロストしないか65
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
事例例Cloudian
RedisCassandraHyperStore
httpcloudianjpcloud-storage-productscloudianhtml
66
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Cloudiantradeの論論理理アーキテクチャ
67
Adminサーバー
S3サーバーQoS DB(Redis)
認証情報(Redis)
アカウント情報(Cassandra)
ユーザーデータ(CassandraHyperStore)
レポート(Cassandra)
Servlets管理理コンソール
ログイン
アカウント設定 セキュリティキー
レポート
Data Explorer
HTTPS
HTTPS
HTTP
HTTP
ウェブUI
アプリケーション
HTTP
HTTP or HTTPS (S3)
データサーバー
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
オブジェクトストアとしてのCassandra
bullBLOBストレージbull グループごとに column family を作成
bull 行行キーemsp ltバケットIDgtltオブジェクトIDgt
bullオブジェクトのメタデータbull ACL (アクセスコントロールリスト)オブジェクトのサイズ
bull Cassandra 行行キャッシュを活用
bull巨大なS3オブジェクトのサポート bull マルチパートemsp Amazon S3 multi-‐‑‒part APIを使ってアップロード
bull チャンキングemsp 大きなオブジェクトを小さなチャンク(例例 10MB)に分割して保存
bull HTTPレンジヘッダーemsp ダウンロード時は HEAD リクエストでオブジェクトのサイズを
取得してからスタートのバイト位置と長さを指定してダウンロード
bull HyperStoretradeemsp 巨大なオブジェクトをネイティブなファイルシステムに保存
68
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
大きなデータの扱いで性能が劣劣化
Cassandra 10 28551 9992 379745 155680 1699 3060198
Cassandra 086 34099 8402 1015888 333048 1336 2406446
遅延時間の中央値(ミリ秒)
遅延時間の中央値(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒)
遅延時間の95パーセンタイル値
(ミリ秒) スループット(件秒)
30分間で処理理した件数
Get Put Get Put
スループット(件秒)
30分間で処理理した件数
Cassandra 10 1016 0949 2476 4789 8748 15755306
Cassandra 086 1282 0948 5729 2243 8700 15668017
バリューサイズ 1KB
出典「NOSQLの基礎知識識」emsp リックテレコム2012年年4月出版
バリューサイズ 100KB
69
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStoretrade(特許出願中)HyperStorebullストレージのハイブリッド化により処理性能とディスク利用効率の向上を実現
bullオブジェクトの大きさに応じて最適なストレージを自動選択
bull メタデータは引き続きCassandraに格納
bull パーティショニングレプリケーションノードの死活監視はCassandraの分散機能を使用
Adminサーバー
S3サーバー
QoS(Redis)
認証情報(Redis)
Accounting(Cassandra)
Data Store(Cassandra)
Reporting(Cassandra)
Cloudianサーバー
データストア
HyperStoretradeManager
70
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
HyperStore レイテンシーの測定
0
125
250
375
500
0 1 10 100 1000KB
PUT-CassPUT-HS
ms
0
150
300
450
600
0 1 10 100 1000
GET-CassGET-HS
ms
gt30 faster
gt400 faster
KB
71
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
推薦図書
72
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NOSQLの基礎知識識
ビッグデータを活かすデータベース技術本橋信也 (著)河野達也 (著)鶴見見利利章 (著)太田 洋 (監修)
256ページ出版社 リックテレコム (2012425)ISBN-‐‑‒10 4897978874ISBN-‐‑‒13 978-‐‑‒4897978871
73
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLデータベースファーストガイド佐々木 達也 (著)
MongoDBRedis
232ページ出版社 秀和システム (201104)ISBN-‐‑‒10 4798029599ISBN-‐‑‒13 978-‐‑‒4798029597
74
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
NoSQLプログラミング実践活用技法Shashank Tiwari (著)中村 泰久 (監修)長尾 高弘 (翻訳)
HBaseCassandraMongoDBRedis
407ページ出版社 翔泳社 (2012518)ISBN-‐‑‒10 4798126055ISBN-‐‑‒13 978-‐‑‒4798126050
75
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
まつもとゆきひろコードの未来まつもと ゆきひろ (著)
MongoDBVoltDB
360ページ出版社 日経BP社 (2012517)ISBN-‐‑‒10 4822234630ISBN-‐‑‒13 978-‐‑‒4822234638
76
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
この勉強会を終えると(再)
bullNOSQL製品を分類するためのキーワードが理理解できる
bull主要な製品の特徴が説明できるbullNOSQLの使いどころが説明できる
77
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
Questions
httpgplustotatsuya6502
httptwittercomtatsuya6502
78
Slides httpbitlyjdmc-‐‑‒nosqlhttpsgithubcomtatsuya6502nosql-‐‑‒jatreejdmc-‐‑‒jul-‐‑‒2013slides
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません
Cloudian Inc amp KK ndash Except where otherwise noted content on this document is licensed under a Creative Commons Attribution-NonCommercial 30 Unported License
クリエイティブコモンズ表示 -‐‑‒ 非営利利 30 非移植 ライセンスCC Attribution-‐‑‒NonCommercial 30 Unported License
79
bull この文書は クリエイティブコモンズ 表示-‐‑‒非営利利 30 非移植 (CC BY-‐‑‒NC 30) ライセンス の下に提供されています使用許諾諾条件を見見るにはhttpcreativecommonsorglicensesby-‐‑‒nc30 をチェックしてください
bull あなたは以下の条件に従う場合に限り自由に
bull 本作品を複製頒布展示実演することができます
bull 二次的著作物を作成することができます
bull あなたの従うべき条件は以下の通りです
bull 表示 mdash あなたは原著作者のクレジットを表示しなければなりません
bull 非営利利 mdash あなたはこの作品を営利利目的で利利用してはなりません