awsのデータベース入門 · •...

57
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 片岡 光康 Solutions Architect, Amazon Web Services Japan K.K. 2-H1-1-13 AWSのデータベース入門

Upload: others

Post on 16-Sep-2019

2 views

Category:

Documents


0 download

TRANSCRIPT

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

片岡光康

Solutions Architect, Amazon Web Services Japan K.K.

2-H1-1-13

AWSのデータベース入門

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

自己紹介

・片岡光康(かたおかみつやす)

・アマゾンウェブサービスジャパン株式会社

技術本部西日本担当

ソリューションアーキテクト

・好きなAWSサービス

Amazon Simple Storage Service (S3)

Amazon WorkSpaces

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSのデータベースサービス

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSのデータベースサービスRelational Databases Non-Relational Databases

Amazon

RDS

Amazon

DynamoDB

Amazon

ElastiCache

Amazon

Redshift

AWS Database Migration Service (DMS)

Amazon

Neptune

Aurora Commercial Community

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

どれを使えば良い?

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

各サービスご紹介

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon RDS

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

• フルマネージドな

リレーショナルデータベース

• シンプルかつ迅速にスケール

• 高速、安定したパフォーマンス

• 低コスト、従量課金

Amazon

RDS

Amazon RDS 概要

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

オンプレミス On EC2 RDS

リレーショナルデータベースのデプロイメントモデル

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

データベース管理のフルマネージド化による運用負荷の軽減

Power, HVAC, net

Rack & stack

Server maintenance

OS patches

DB s/w patches

Database backups

Scaling

High availability

DB s/w installs

OS installation

App optimization

Power, HVAC, net

Rack & stack

Server maintenance

OS patches

DB s/w patches

Database backups

Scaling

High availability

DB s/w installs

OS installation

App optimization

Power, HVAC, net

Rack & stack

Server maintenance

OS patches

DB s/w patches

Database backups

Scaling

High availability

DB s/w installs

OS installation

App optimization

オンプレミス On EC2 RDS

お客様

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

データベース管理者(DBA)はより付加価値の高い仕事に集中できる

・バックアップスクリプトの作成、仕掛け

・障害時のフェイルオーバー運用、障害サーバーの再構築

・パッチ適用やスケールのためのメンテナンス作業

・各種ログ・メトリクスの可視化、アラート設定

・ハードウェア、ソフトウェアの保守切れによるマイグレーション

これまでのDBA

・各データベースエンジンの特性を理解して、パフォーマンスをチューニング

・ログ・メトリクスからボトルネックを特定、解消

・新しい施策に向けた検証やベンチマーク

・データベースを中心とした全体的なシステムアーキテクト

これからのDBA

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon RDSのユースケース例

• トランザクション処理

• 複合クエリー処理

• データベースサイズが 16 TB未満

• ワークロードがシングルノードで処理可能(リードレプリカでの負荷分散を含む)

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Aurora

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

• フルマネージドな

リレーショナルデータベース

• シンプルかつ迅速にスケール

• 高速、安定したパフォーマンス

• 低コスト、従量課金

Amazon

RDS

Amazon RDS 概要

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Aurora の特徴

ハイパフォーマンス

フルマネージド 高可用性・高耐久性セキュリティにも配慮

MySQL 5.6, 5.7

PostgreSQL 9.6互換スケーラブル

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

WRITE PERFORMANCE READ PERFORMANCE

MySQL SysBench results

R3.8XL: 32 cores / 244 GB RAM

5X faster than RDS MySQL 5.6 & 5.7

SysBenchを用いたベンチマークにおいて

MySQLと比較して 5倍高いスループットを計測

0

25,000

50,000

75,000

100,000

125,000

150,000

0

100,000

200,000

300,000

400,000

500,000

600,000

700,000

Aurora MySQL 5.6 MySQL 5.7

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

WRITE PERFORMANCE READ PERFORMANCE

インスタンスサイズによるスケール

AuroraはRead/Writeパフォーマンス共にインスタンスサイズに比例してスケール

Aurora MySQL 5.6 MySQL 5.7

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Aurora のアーキテクチャ

ログとストレージレイヤを

シームレスにスケールする

ストレージサービスに移動

管理コンポーネントにEC2,

Amazon DynamoDB, Amazon

SWFなどのAWSサービスを採用

Amazon S3を利用して99.999999999%の耐久性でストリーミングバックアップ

Data Plane

Logging + Storage

SQL

Transactions

Caching

Amazon S3

Control Plane

Amazon

DynamoDB

Amazon SWF

Amazon

Route 53

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

キャッシュレイヤの分離

• キャッシュをデータベースプロセ

ス外に移動

• データベースプロセスのリスター

トが発生してもキャッシュが残っ

た状態を維持可能

• データベースをすぐサービスに戻

すことが出来る

• 高速なクラッシュリカバリ + 保持

可能なキャッシュ = DB障害から

高速に復帰可能

SQL

Transactions

Caching

SQL

Transactions

Caching

SQL

Transactions

Caching

キャッシュプロセスをDBプロセス外におくことでDBプロセスの再起動でもキャッシュが残る

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Auroraのストレージ

SSDを利用したシームレスにスケールするストレージ

• 10 GBから64 TBまでシームレスに自動でスケールアップ

• 実際に使った分だけ課金

標準で高可用性を実現

• 3AZに6つのデータのコピーを作成

Log Structured Storage

SQL

Transactions

AZ 1 AZ 2 AZ 3

Caching

Amazon S3

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

ディスク障害検知と修復

• 2つのコピーに障害が起こっても、読み書きに影響は無い• 3つのコピーに障害が発生しても読み込みは可能• 自動検知、修復

SQL

Transaction

AZ 1 AZ 2 AZ 3

Caching

SQL

Transaction

AZ 1 AZ 2 AZ 3

Caching

読み書き可能 読み込み可能

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Auroraのストレージの特徴

リードレプリカもマスタと同じストレージを参照

64TBまで自動でストレージがシームレスにスケールアップ

• パフォーマンスや可用性に影響無し・利用開始時のプロビジョニング不要

• 実際に使った分だけ課金

継続的なS3へ増分バックアップ

• パフォーマンスへの影響なし

自動で再ストライピング、ミラー修復、ホットスポット管理、暗号化

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Auroraのユースケース例

• トランザクション処理

• 複合クエリー処理

• データベースサイズが 16 TBを超える

• ワークロードがマルチノードを必要とする(リードレプリカでの負荷分散を含む)

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Redshift

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Redshiftの概要

クラウド上のDWH• 数クリックで起動• 使った分だけの支払い• 運用管理の手間が少ない

高いパフォーマンス• ハイ・スケーラビリティ

高い汎用性• PostgreSQL互換のSQL

• 多くのBIツールがサポート

コンピュートノード

コンピュートノード

コンピュートノード

リーダーノード

SQLクライアントBIツール

JDBC/ODBC

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

MPPとシェアードナッシングがスケールアウトの鍵

MPP : Massive Parallel Processing• 1つのタスクを複数のノードで分散して実行する仕組み• Redshiftではリーダーノードがタスクをコンピュートノードに分散して実行する

• ノードを追加する(スケールアウト)でパフォーマンス向上可能

シェアードナッシング• ディスクをノードで共有しない構成• ディスクを共有するとノード数が増えた時にボトルネックになるため、それを回避

• ノードとディスクがセットで増えていく

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Redshiftの構成①

SELECT *

FROM lineitem;リーダーノードがクライアントからSQLを受け取る

CPU CPU CPU CPU CPU CPU

Leaderノード

Computeノード

1つの表を各ノードのストレージに分散して保存(シェアードナッシング)

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Redshiftの構成②

SELECT *

FROM lineitem;

SQLをコンパイル、コードを生成し、コンピュートノードへ配信

CPU CPU CPU CPU CPU CPU

Leaderノード

Computeノード

スライス=メモリとディスクをノード内で分割した論理的な処理単位

コンピュートノードの追加でパフォーマンス向上(スケールアウト)

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

IOを削減する① -列指向型(カラムナ)

・行指向型(他RDBMS) ・列指向型(Redshift)

orderid name price

1 Book 100

2 Pen 50

n Eraser 70

orderid name price

1 Book 100

2 Pen 50

n Eraser 70

DWH用途に適した格納方法

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

IOを削減する② -圧縮

データは圧縮してストレージに格納される

カラムナのため類似したデータが集まり、高い圧縮率

エンコード(圧縮アルゴリズム)は列ごとに選択可能

COPYコマンドやANALYZEコマンドで圧縮アルゴリズムの推奨を得ることが可能

エンコードタイプCREATE TABLE およびALTER TABLE のキーワード

データ型

raw (非圧縮) RAW すべて

バイトディクショナリ BYTEDICT BOOLEAN 以外のすべて

デルタDELTA

DELTA32K

SMALLINT、INT、BIGINT、DATE、TIMESTAMP、DECIMAL

INT、BIGINT、DATE、TIMESTAMP、DECIMAL

LZO LZO

BOOLEAN、REAL、および DOUBLE PRECISION

以外のすべて

Mostlyn

MOSTLY8

MOSTLY16

MOSTLY32

SMALLINT、INT、BIGINT、DECIMAL

INT、BIGINT、DECIMAL

BIGINT、DECIMAL

ランレングス RUNLENGTH すべて

テキストTEXT255

TEXT32K

VARCHAR のみVARCHAR のみ

Zstandard ZSTD すべて

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

IOを削減する③ -ゾーンマップ

Redshiftは「ブロック」単位でディスクにデータを格納。1ブロック=1MB

ブロック内の最小値と最大値をメモリに保存

不要なブロックを読み飛ばすことが可能

10 | 13 | 14 | 26 |…

… | 100 | 245 | 324

375 | 393 | 417…

… 512 | 549 | 623

637 | 712 | 809 …

… | 834 | 921 | 959

10

324

375

623

637

959

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

フルマネージドサービス

設計・構築・運用の手間を削減

数クリックで起動

1時間単位の費用

ノード数やタイプは後から変更可能

バックアップやモニタリング機能を内蔵GUI(マネジメントコンソール)

API経由で操作も可能

パッチ適用も自動的メンテナンスウィンドウでパッチの時間帯を指定可能

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

運用機能

データ更新・挿入S3, DynamoDB等からの高速並列ロード

INSERT/UPDATE/DELETEでの操作も可能

バックアップ&リストアS3へ差分で保存

バックアップ中もSQLを実行可能

自動スナップショット

スナップショットから新しいクラスタへリストア

他リージョンのS3への自動レプリケーション

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Redshiftのユースケース例

• 分析、レポーティング

• DWH & BI

• バッチ処理による大量更新

• ペタバイトクラスのデータ

• データ圧縮、列指向型

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon DynamoDB

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

DynamoDBの特長

• 完全マネージド型の NoSQL データベースサービス

• ハイスケーラブル、低レイテンシー

• 管理不要で信頼性が高い

• プロビジョンドスループット

• ストレージの容量制限がない

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

特長1:管理不要で信頼性が高い

SPOFの存在しない構成

データは3箇所のAZに保存されるので信頼性が高い

ストレージは必要に応じて自動的にパーティショニングされる

クライアント

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

特長2:プロビジョンドスループットテーブルごとにReadとWriteそれぞれに対し、必要な分だけのスループットキャパシティを割り当てる(=プロビジョンする)ことができる

例えば下記のようにプロビジョンするRead : 1,000回/秒

Write : 100回/秒

書き込みワークロードが上がってきたら…

Read : 500回/秒

Write : 1,000回/秒

この値はDB運用中にオンラインで変更可能ただし、スケールダウンに関しては日に9回までしかできないので注意が必要

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

特長3:ストレージの容量制限がない

使った分だけの従量課金制のストレージ

データ容量の増加に応じたディスクやノードの増設作業は一切不要

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon DynamoDB その他機能

• バックアップ/リストア(オンデマンド、PITR)

• Global Tables

• Auto Scaling

• DynamoDB Accelerator (DAX)

• Time to Live (TTL)

• セキュリティ対応(Encryption At Rest)• Encryption-In-Transit: クライアントとDynamoDB間の通信暗号化

• Encryption-At-Rest: ディスク上のデータ暗号化

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon DynamoDBのユースケース例

• キーバリュー型 or シンプルなクエリー

• 高速なパフォーマンス

• シームレスに大規模までスケール

• サイズとスループット制限なし

• などなど…

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon ElastiCache

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon ElastiCacheの特徴

• パフォーマンス• 超高速な2種類のエンジン(redis、memcached)をサポート

• AmazonによるRedisの機能拡張

• フルマネージド• キャッシュクラスタを数クリックで起動

• 可用性を向上させる機能(モニタリング、自動障害検出、復旧、拡張、パッチ適用、バックアップ)

• 高可用性と堅牢性• VPC対応、セキュリティグループ、暗号化

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon ElastiCacheのユースケース例

• キャッシング• 構造化データ(例:RDS)・準構造化データ(例:MongoDB)・非構造データ(例:S3)などをキャッシュする事で、レイテンシー・スループットを改善

• チャットとメッセージング• パターンマッチングを備えたPUB/SUB 標準をサポートしているため、高性能なチャットルーム、コメントストリーミングが可能

• セッションストア

• などなど…

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Neptune

(Preview)

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Neptune の特徴

グラフデータベース

フルマネージド

ハイパフォーマンス

高いスケーラビリティ

Gremlin と SPARQLでクエリ可能

Apache TinkerPopとW3C RDF が利用可能

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Neptune とは

• 高速• 億レベルのリレーションシップをミリ秒のレイテンシで問合せ可

• 高信頼性• 3つのAZに跨がる6つのレプリカをフルバックアップ/リストアと共に提供

• 簡単• GremlinとSPARQLによる簡単でパワフルなクエリを実行

• オープン• Apache TinkerPop & W3C RDF グラフモデルをサポート

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Amazon Neptuneのユースケース例

• ソーシャルネットワーキング

• 推奨エンジン

• 不正検出

• など…

データ間のリレーションシップを作成し、そのリレーションシップに対してすばやくクエリを実行する必要があるユースケースで、リレーショナルデータベースよりも優れた威力を発揮

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

まとめ

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

どれを使えば良い?

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSのデータベースサービスRelational Databases Non-Relational Databases

Amazon

RDS

Amazon

DynamoDB

Amazon

ElastiCache

Amazon

Redshift

AWS Database Migration Service (DMS)

Amazon

Neptune

Aurora Commercial Community

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSのデータベースサービスRelational Databases Non-Relational Databases

Amazon

RDS

Amazon

DynamoDB

Amazon

ElastiCache

Amazon

Redshift

AWS Database Migration Service (DMS)

Amazon

Neptune

Aurora Commercial Community

トランザクション処理、複合クエリー処理を

優先するのであれば Relational Databases を、

そうでなければ Non-Relational Databases を検討

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSのデータベースサービス (Relational Databases)

Relational Databases

Amazon

RDS

Amazon

Redshift

AWS Database Migration Service (DMS)

Aurora Commercial Community

トランザクション処理汎用用途

DWH

大容量分析・集計

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSのデータベースサービス (Amazon RDS)

Amazon RDS

AWS Database Migration Service (DMS)

Aurora Commercial Community

利用コストアプリ開発者の習熟度

開発スピード (新機能 / 不具合修正)

既存システムとの互換性

パフォーマンス高い対障害性大容量など

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSのデータベースサービス (Non-Relational Databases)

Non-Relational Databases

Amazon

DynamoDB

Amazon

ElastiCache

AWS Database Migration Service (DMS)

Amazon

Neptune

3拠点にレプリケーションSSDに永続化

DAXによる読み込み高速化

インメモリ低レイテンシ

高速なグラフデータベース高信頼性オープン

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

ご要件と特徴がマッチしたサービスを

ご利用ください

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

ありがとうございました