introduction to documentdb
DESCRIPTION
JAZUG仙台 - JAZUG4周年を祝う会 in 仙台 Introduction to DocumentDB tunable consistency に関する解説TRANSCRIPT
JAZUG 仙台 - JAZUG4 周年を祝う会 in 仙台
Introduction to DocumentDB
kyrt / Takekazu Omi
http://kyrt.in
@takekazuomi
2014/9/20 1.0.0
Azure DocumentDB
kyrt @takekazuomi 22014/9/20
自己紹介
近江 武一JAZUG Azure Storage 担当(自称)
Microsoft MVP for Azure
kyrt @takekazuomi 3
kyrt.in
github.com/takekazuomiwhite
paper
2014/9/20
kyrt @takekazuomi 4
CDP Azure 本の紹介• Microsoft patterns & practices
• Cloud Design Patterns: Prescriptive Architecture Guidance for Cloud Applications• http://
msdn.microsoft.com/en-us/library/dn568099.aspx• 翻訳が、2014年6月に出ました
• クラウドデザインパターン Azureを例としたクラウドアプリケーション設計の手引き• http://ec.nikkeibp.co.jp/item/books/P98330.html• 日経BP
以下、CDP本と記述2014/9/20
kyrt @takekazuomi 5
Introduction to Azure DocumentDBDocumentDB 入門
2014/9/20
最新 News
• 8/21 preview 開始で25日目• New DocumentDB quotas(今朝)
• http://blogs.msdn.com/b/documentdb/archive/2014/09/20/new-documentdb-quotas.aspx
• Number of stored procedures, triggers and UDFs per collection• 5->25 each
• Maximum request size of document and attachment• 16KB -> 256KB
• Maximum number of AND/OR clauses per query 3-> 5• https://
github.com/Azure/azure-content/commit/16b49c3df1e9cccdfdaca3a669a89d287cf41c82
kyrt @takekazuomi 62014/9/20
概要
•NoSQL•スキーマレス•SQL によるクエリ•SSD backend•native JSON ドキュメント•REST API で操作•高いスケーラビリティとパフォーマンス
kyrt @takekazuomi 72014/9/20
「過去 1 年間にわたって、 Microsoft 内部で、いくつかの注目されているサービスに対して DocumentDB を使ってきました。現在では、それぞれのサイズが数百 TB であり、 1 桁ミリ秒の短い待機時間の予測可能なパフォーマンスで、それぞれ一日あたり数百万の複雑な DocumentDB クエリを処理・・・ ・・・ 」
• 引用: ScottGu’s Blog > Azure: New DocumentDB NoSQL Service, New Search Service, New SQL AlwaysOn VM Template, and more• http://
weblogs.asp.net/scottgu/azure-new-documentdb-nosql-service-new-search-service-new-sql-alwayson-vm-template-and-more
• http://satonaoki.wordpress.com/2014/08/25/azure-docdb-search/kyrt @takekazuomi 82014/9/20
Microsoft Azure Data Services
kyrt @takekazuomi 92014/9/20
出典: http://channel9.msdn.com/Shows/Data-Exposed/Introduction-to-Azure-DocumentDB
Microsoft Azure Data Services
kyrt @takekazuomi 102014/9/20
出典: http://channel9.msdn.com/Shows/Data-Exposed/Introduction-to-Azure-DocumentDB
full managed, scalable, queryable, schemafree JSON document database service for modern application
schema freeSQL like な簡潔な文法で階層化された JSON data を queryJavaScript expression evaluation, projections, filtering, joins
JavaScript as a
modern T-SQL
collection の stored script では、 ACID トランザクションをサポートJavaScript で、 procedure, UDF, trigger を記述
tunable consistency
アプリケーションのシナリオとパフォーマンス要求に応じて整合性を調整
full managed
VM や cluster infrastructure の管理不要
kyrt @takekazuomi 112014/9/20
Resource Model
kyrt @takekazuomi 122014/9/20
DEMO
2014/9/20 kyrt @takekazuomi 13
fast, scalable, available
2014/9/20 kyrt @takekazuomi 14
tunable consistency整合性の調整
2014/9/20 kyrt @takekazuomi 15
tunable consistency levels
•Strong•強い整合性、 read/write で大きなレイテンシー、 SQL Database
と同じ•Bounded Staleness• write は最適なレイテンシー、 read で予測可能な整合性
•Session• Session 内では read/write では最新の結果を保証
•Eventual•結果整合性、 read は一時的に古いデータを返すことがある。 read/write で最も低い latency
kyrt @takekazuomi 162014/9/20
前提
•Replication の話•システムは複数の replica から構成•write の伝搬は時間がかかる (=lagged)• read で replica を使う (=low latency, more scale)
•Client からの見た時の整合性•システム全体の整合性が失われている状態を Clientにどう見せるか (visibility)
kyrt @takekazuomi 172014/9/20
同期 replication遅い
じゃあ、非同期非整合
kyrt @takekazuomi 182014/9/20
2014/9/20 kyrt @takekazuomi 19
latency
consistency
• replica, N=3•Client A がwrite request•Client B が read request•W rite request•write A ck•R ead request• read re S ponse
kyrt @takekazuomi 202014/9/20
注目① W→ A の間の
時間② R で何処にア
クセスするかWARS
kyrt @takekazuomi 212014/9/20
Strong
• 強い一貫性では、書込結果がレプリカの majority quorum に永続的にコミットされた後にだけ見えるようになる• 書込は同期的にプライマリとセカンダリの quorum の両方に永
続的にコミット(もしくはアボートされる)• 読み込みは、承認された majority read quorum から行われる。
クライアントには、未コミットあるいは書込中のデータは見えない。書込で最後に ack が返ったものを読むことが保証される。• 強い整合性は、完全なデータの整合性を保証する。しかし、低い
レベルの読み込み、書込パフォーマンス
kyrt @takekazuomi 222014/9/20
Strong
•N=3, W=2, R=2•2+2>3
安全だが、 latency cost が高い
strong consistency は latency 大きいkyrt @takekazuomi 232014/9/20
Eventual
•Eventual consistency は、もっとも弱い一貫性•クライアントは一時的に以前見たものより古い値を見ることがある•それ以降の書込が無い場合は、レプリカは最終的に収束する• read request は、任意の secondary で処理される•Eventual は、 weakest read consistency を提供し、 read/write の両方で lowest latency となる
kyrt @takekazuomi 242014/9/20
Eventual
•N=3,W=R=1•1+1≯ 3
maximum possible performanceデータ喪失、 read 不整合
kyrt @takekazuomi 252014/9/20
新しい整合性レベルSession と、 Bounded Staleness
2014/9/20 kyrt @takekazuomi 26
2014/9/20 kyrt @takekazuomi 27
latency
consistency
tunable
Session• strong や bounded staleness consistency levels が提供するようなglobal
consistency models ではない。 “session” consistency は、特定のクライアントで成立
• 同一 session内で書かれた最新の結果が read
• read request は、client が要求したバージョン( session cookie の一部に入っている)を提供できるレプリカへ発行
• セッションの整合性に対するリード要求が(セッションクッキーの一部)は、クライアント要求されたバージョンを提供することができるレプリカに送られる
• Session は、 lowest latency writes で、予測可能な read data consistency を提供• ReadもReadがsingle replicaであるような 特殊な場合を覗いて low latency となる
kyrt @takekazuomi 282014/9/20
•システム全体の整合性を配慮しない•Session に参加している Client 間のみの整合性•replica への伝搬初期の heavy read にパフォーマンスペナルティ
DocumentDB のデフォルト
kyrt @takekazuomi 292014/9/20
Bounded Staleness
• Bounded Staleness 整合性では書込の順番を保証するが読み込みは最大K操作の遅れがある• read request は常に replicaのmajority quorum を返す• read response は、 request で指定された時間内に収まるようなもっと
も新しいものを返す• 低いwrite latency と、より予測可能な read consistency を提供• majority quorum からの読み込み応答になるので、 read latency は
lowest ではない• K は、operationの数 (MaxStalenessPrefix)と時間(秒、
MaxStalenessIntervalInSeconds)で指定kyrt @takekazuomi 302014/9/20
Azure Portal の設定
kyrt @takekazuomi 312014/9/20
Query Consistency
• デフォルトでは、ユーザー定義のリソースに対するクエリの整合性レベルは、読み取りの場合と同じ• デフォルトでは、 indexは、 collection の documentの、各 insert,
replace, deleteで、同期的に更新• queryは、document reads と同じ整合性レベルで実行• DocumentDBでは、特定のcollectionで indexの遅延更新で、write
optimized と、documentの継続的な(だらだらとした)書込(sustained volumes of document writes)をサポート• Lazy indexing は、書込パフォーマンスをブースト• primarily read-heavy なワークロードでのバクルロードに最適
kyrt @takekazuomi 322014/9/20
Query ConsistencyINDEXING MODE READS QUERIES
Consistent (default)
Strong, Bounded Staleness, Session, Eventual から選択
Strong, Bounded Staleness, Session, Eventual から選択
Lazy Strong, Bounded Staleness, Session, Eventual から選択
Eventual
• read request と同じように、 [x-ms-consistency-level] のリクエストヘッダーを指定することによって、特定の query request の整合性レベルを下げることができる
kyrt @takekazuomi 332014/9/20
最後に
2014/9/20 kyrt @takekazuomi 34
•整合性レベルに選択肢があるのは面白い•Session は普通に使えそう、 Session ID の共有範囲、方法が課題•Bounded Staleness は、 PBS のサイト「 PBS: Probabilistically Bounded Staleness 」がお勧め• http://pbs.cs.berkeley.edu/
•Riak がとても良い感じ• http://basho.com/
kyrt @takekazuomi 352014/9/20
Bookmarks
2014/9/20 kyrt @takekazuomi 36
kyrt @takekazuomi 37
• ScottGu’s Blog > Azure: New DocumentDB NoSQL Service, New Search Service, New SQL AlwaysOn VM Template, and more• http://satonaoki.wordpress.com/2014/08/25/azure-docdb-search /• http://weblogs.asp.net/scottgu/azure-new-documentdb-nosql-service-new-search-s
ervice-new-sql-alwayson-vm-template-and-more
• Introducing Azure DocumentDB – Microsoft’s fully managed NoSQL document database service• http://blogs.msdn.com/b/documentdb/archive/2014/08/22/introducing-azure-docu
mentdb-microsoft-s-fully-managed-nosql-document-database-service.aspx
• Azure DocumentDB Team blog• http://blogs.msdn.com/b/documentdb/
• MicrosoftがMicrosoft Azure向けのドキュメントデータベースを発表• http://www.infoq.com/jp/news/2014/09/microsoft-azure-documentdb
• Microsoft unveils Azure DocumentDB, a NoSQL database as a service• https
://gigaom.com/2014/08/21/microsoft-unveils-documentdb-a-nosql-database-built-for-azure/
2014/9/20
• Introduction to Azure DocumentDB• http://
channel9.msdn.com/Shows/Data-Exposed/Introduction-to-Azure-DocumentDB
• How to create a DocumentDB account• http://azure.microsoft.com/en-us/documentation/articles/documentdb-create-ac
count/
• Query DocumentDB• http://azure.microsoft.com/en-us/documentation/articles/documentdb-sql-query /
• Consistency levels in DocumentDB• http
://azure.microsoft.com/en-us/documentation/articles/documentdb-consistency-levels/
• DocumentDB Limits for the Preview Release• http://azure.microsoft.com/en-us/documentation/articles/documentdb-limits /
• DocumentDB programming: Stored procedures, triggers, and UDFs• http://azure.microsoft.com/en-us/documentation/articles/documentdb-program
ming/kyrt @takekazuomi 382014/9/20
• Interact with DocumentDB Resources• http://azure.microsoft.com/en-us/documentation/articles/documentdb-intera
ctions-with-resources/
• Build a web application with ASP.NET MVC using DocumentDB• http
://azure.microsoft.com/en-us/documentation/articles/documentdb-dotnet-application/
• Build a Node.js web application using DocumentDB• http://azure.microsoft.com/en-us/documentation/articles/documentdb-nodej
s-application/
• Manage DocumentDB capacity and performance• http://azure.microsoft.com/en-us/documentation/articles/documentdb-mana
ge/
• Monitor a DocumentDB account• http://azure.microsoft.com/en-us/documentation/articles/documentdb-monit
or-accounts/
kyrt @takekazuomi 392014/9/20
•Azure DocumentDB .NET Code Samples• http://
code.msdn.microsoft.com/Azure-DocumentDB-NET-Code-6b3da8af
•The Bw-Tree: A B-tree for New Hardware• http://research.microsoft.com/apps/pubs/default.aspx?id=178758
•High-Performance Concurrency Control Mechanisms for Main-Memory Databases• http://research.microsoft.com/apps/pubs/default.aspx?id=156645
•Hekaton: SQL Server’s Memory-Optimized OLTP Engine• http://research.microsoft.com/apps/pubs/default.aspx?id=193594
kyrt @takekazuomi 402014/9/20
kyrt @takekazuomi 41
終2014/9/20