More Related Content
Similar to [AWSマイスターシリーズ] Amazon ElastiCache
Similar to [AWSマイスターシリーズ] Amazon ElastiCache (20)
More from Amazon Web Services Japan
More from Amazon Web Services Japan (20)
[AWSマイスターシリーズ] Amazon ElastiCache
- 1. re:G
ene
AWS マイスターシリーズ
rate
Amazon ElastiCache
2013.10.30
アマゾンデータサービスジャパン株式会社
ソリューションアーキテクト 松尾 康博
ソリューションアーキテクト 蒋 逸峰
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 2. アジェンダ
!
!
!
!
!
!
メモリキャッシュとは
Amazon ElastiCacheの概要
ElastiCache for Memcached
ElastiCache for Redis
ユースケース
まとめ
2
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 3. メモリキャッシングとは
! 目的
• アプリを高速化する手法の一つ
• 消えても良いデータを格納してDBアクセス・負荷を低減
• メモリにキャッシュしたデータを再利用し 低遅延化・負荷低減
! 用途
• クエリ結果を再利用 (DBサーバの負荷低減、高速化)
• 揮発性の高いデータを格納 (セッション情報管理)
• 複雑な計算結果・二次データを再利用 (APPサーバの負荷軽減)
3
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 4. Web+DBアプリとメモリキャッシュ
! 典型的な構成
App
RDBMS
1. クライアントからのリクエスト
2. Appサーバが、DBサーバに問い合わせ
3. DBサーバが結果を戻す
4. Appサーバがレスポンスをクライアントに返す
4
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 5. Web+DBアプリとメモリキャッシュ
! トラフィックが増えると
App
RDBMS
App
RDBMS
5. Appサーバ,DBサーバをスケール
6. 効果・効率・コスト的な面、DBをスケールさせる難易度は?
5
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 6. Web+DBアプリとメモリキャッシュ
! DB負荷を軽減するためにキャッシュにデータを載せる
• アプリケーション側で、DBとキャッシュを使い分ける
App
RDBMS
App
キャッシュ
6
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 8. Web+DBアプリとメモリキャッシュ
! 更更新時の操作
キャッシュ
Insert / Update
App
RDBMS
オブジェクト書き込み
繰り返し
8
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 9. Webアプリとメモリキャッシュ(セッション)
! 共有キャッシュとして使った構成
§ 複数のAppサーバで共有するセッション用メモリ空間を実現
§ 多くの言語やフレームワークが対応済み
§ セッションレプリケーションやロードバランサに依存しない構成が可能
App
キャッシュ
LB
App
9
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 10. アジェンダ
!
!
!
!
!
!
メモリキャッシュとは
Amazon ElastiCacheの概要
ElastiCache for Memcached
ElastiCache for Redis
ユースケース
まとめ
10
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 11. AWSの様々なサービス
お客様のアプリケーション
ライブラリ & SDKs
Java, PHP, .NET,
Python, Ruby,
node.js
IDEプラグイン
Eclipse
Visual Studio
メッセージ
Amazon SNS
Amazon SQS
Amazon SES
コンテンツ配信
Amazon CloudFront
コンピュータ処理理
Amazon EC2
Auto Scale
Web管理理画⾯面
Management
Console
認証
AWS IAM
デプロイと⾃自動化
モニタリング
Amazon
CloudWatch
検索索エンジン
Amazon Cloud Search
分散処理理
AWS Elastic Beanstalk
AWS Cloud Formation
AWS OpsWorks
Development &
Administration
ワークフロー管理理
Amazon SWF
トランスコード
Elastic MapReduce
Amazon Elastic Transcoder
ストレージ
Amazon S3
Application
Service
データベース
Amazon EBS
Amazon Glacier
AWS Storage Gateway
Amazon RDS
Amazon DynamoDB
Amazon ElastiCache
Amazon Redshift
Infrastructure
Service
ネットワーク & ルーティング
Amazon VPC / Amazon Elastic Load Balancer / Amazon Route 53 /AWS Direct Connect
Region
11
AZ
AWS グローバルインフラ
Geographical Regions, Availability Zones, Points of Presence
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 13. 典型的Webアーキテクチャ(他のサービスとの組み合わせ)
CloudFront
(コンテンツ
配信)
Amazon Route 53
(ドメイン名割り当て)
東京リージョン
ELB
(ロードバランサ)
AZ-‐‑‒1c
AZ-‐‑‒1a
EC2
EC2
S3
静的コンテンツ
RDSマスタ
⾃自動同期
RDSスレーブ
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 14. Amazon ElastiCacheとは
! 構築
• キャッシュクラスタを数クリックで起動
• EC2同様、初期費用無し、時間単位の従量課金
! 移行
• 2種類のエンジン(memcached, redis)をサポート
• 既存アプリケーションの変更不要
! 運用
• 可用性を向上させる機能
• モニタリング、自動障害検出、復旧、拡張、パッ
チ管理機能を提供
! セキュリティ
• セキュリティグループ、VPC対応
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 15. Memcached/Redis on EC2 との相違点
! 導入
§
§
§
§
ノード用インスタンスのOSセットアップ 不要
memecached/ Redisのインストール・セットアップ 不要
複数キャッシュノードへのコンフィグファイル配布・同期不要
Management Console/CLI/APIから数分で起動・ノード追加
! 運用
§ 監視・高可用性の作り込み不要
§ ノードリカバリ、パッチ適用 自動
§ Firewallの用意、詳細設定不要
! AWS独自の用語・概念
§ セキュリティ関連
§ クラスタ関連
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 16. キャッシュノードタイプ
128
Hi-Mem 2XL 33.4 GB
13 EC2 Compute Units
4 virtual cores
64
Memory (GB)
Hi-Mem 4XL 68 GB
26 EC2 Compute Units
8 virtual cores
32
16
8
4
Medium 3.35 GB
2 EC2 Compute Unit
1 virtual core
1
16
2
1
2
4
8
16
Hi-Compute 6.6 GB
20 EC2 Compute Units
8 virtual cores
Large 7.1 GB
4 EC2
Compute Units
2 virtual cores
Micro 213 MB
Up
to 2 ECUs
(for short bursts)
Enhanced XL 14.6 GB
13 EC2 Compute Units
4 virtual cores
Extra Large 14.6 GB
8 EC2 Compute Units
4 virtual cores
Small 1.3 GB
1 EC2 Compute Unit
1 virtual core
Enhanced 2XL 29.6 GB
26 EC2 Compute Units
8 virtual cores
Hi-Mem XL 16.6 GB
6.5 EC2 Compute Units
2 virtual cores
32
64
128
EC2 Compute Units (ECU)
http://aws.amazon.com/jp/elasticache/features-and-benefits/
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 17. キャッシュノードタイプとキャッシュサイズ
Cache Node Type
memcached
(max_̲cache_̲memory)
redis
(maxmemory)
cache.t1.micro
213 MB
136 MB
cache.m1.small
1.3 GB
900 MB
3.35 GB
2.95 GB
7.1 GB
6.7 GB
cache.m1.xlarge
14.6 GB
14.2 GB
cache.m3.xlarge
14.6 GB
※
cache.m3.2xlarge
29.6 GB
※
cache.m2.xlarge
16.7 GB
16.3 GB
cache.m2.2xlarge
33.8 GB
33.4 GB
cache.m2.4xlarge
68 GB
67.6 GB
6.6 GB
6.2 GB
cache.m1.medium
cache.m1.large
cache.c1.xlarge
※ memcached のみサポート
http://aws.amazon.com/jp/elasticache/features-and-benefits/
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 18. CloudWatch対応
! 各種メトリクスを60秒間隔で取得・確認可能
• ホスト層のメトリクス( CPUUtilization, etc. )
• キャッシュエンジン固有のメトリクス(Evict, CurrConnections, etc.)
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/CacheMetrics.html
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 19. イベント通知 (Cache Event)
! ElastiCacheで発生した10以上のイベントをSNS経由でPush通知
• 再起動、ノード追加、ノードリプレイス、設定変更、メンテナンス終了、etc
! 監視システムと組み合わせることで運用自動化が容易に
Queue
Cache
Event
Message
Amazon SNS
ElastiCache
Cache Node
Alarm
Email
Notification
HTTP
Notification
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/ElastiCacheSNS.html
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 20. VPC対応
! VPC内部の任意のサブネットで起動可能
• 起動するサブネットを、Cache Subnet Groupで事前に定義しておく
• Default VPCでは定義済み
! 注意
• 起動するノードに適用する Security Groupを事前に定義しておく
• Public IPはつかない(プライベートIPのみ)
• 起動先のサブネットは、クラスタが起動するに十分なCIDRブロックを
用意しておく。
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/ElastiCacheAndVPC.html
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 21. アクセス制御
! Security Groupで実現
• EC2インスタンスからキャッシュノードへのアクセス制御を実現
• アクセス元 EC2 インスタンスに適用しているSecurity Groupとの紐付けによりア
クセス可能になる
! 注意事項
• ElastiCacheの起動場所によって設定対象が異なる
• VPC Default環境では Cache Security Groupが無い(不要なため)
• Cache Security Groupでは、アクセス元としてSecurity Groupのみ指定可能
起動場所
設定対象
EC2 Classic
Cache Security Group
EC2 VPC
VPC Security Group
VPC Default
VPC Security Group
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/
CacheSecurityGroup.html
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 22. ソフトウェアメンテナンス
! ElastiCache標準機能
• メンテナンスウインドウで指定した曜日・時間帯に自動実施
! メンテナンス内容
• 安全性・堅牢性の関わるソフトウェアパッチを自動適用
• Rebootを伴う場合も
• 自動アップグレードも、メンテナンスウインドウ内で実施
! TIPS
• アプリケーション側で、キャッシュノードへアクセスできない場合のハンドリン
グを実装しておく。
• メンテナンス中は、DBの参照負荷が一時的に上がる可能性が高いため、ト
ラフィックが少ない曜日・時間帯を指定しておく。
• Cache Event 通知を運用監視に組み込んでおく
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/VersionManagement.htmll
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/
ManagingCacheClusters.html#ManagingCacheClusters.MaintWindow
in part without the express consent of Amazon.com, Inc.
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or
- 23. 設定パラメータのカスタマイズ
! パラメータグループ
• 複数のキャッシュノードに一括適用可能なパラメータ群
• キャッシュエンジンごとにデフォルト設定を用意。
! カスタマイズ
• 新たにパラメータグループを作成・編集し、キャッシュクラスタに適用
することでカスタマイズ可能
! 制約事項
• 一部パラメータは、変更不可
• memcached: max_cache_memory, num_threads
• redis: maxmemory
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/
CacheParameterGroups.html
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 24. ElastiCacheの料料⾦金金体系
! キャッシュノード利用時間 ($/時間)
• オンデマンド、リザーブドの2種類の価格モデル
! ネットワーク
• ElastiCache 側では、データ転送課金は発生しません。
• ElastiCacheと通信するEC2側で発生します
• 同一 AZの EC2インスタンスとのデータ転送 : 無料
• 異なるAZのEC2インスタンスとのデータ転送 : $0.01/GB
東京リージョン
$0.01/GB
Availability Zone - a
$0
App
Availability Zone - b
http://aws.amazon.com/jp/elasticache/pricing/
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 25. 2つの価格モデル
! オンデマンド キャッシュノード
• EC2と同様の、初期費用無し、時間単位の従量課金モデル
! リザーブド キャッシュノード
• 予約金を支払うことで時間当たり価格を割引(最大70%節減)
• memcached, redis共に対応
• 購入時に以下を指定
• キャッシュノードクラス (例 cache.m1.xlarge)
• キャッシュエンジン ( memcached or redis)
• 利用率(軽度、中度、重度)
• リージョン (注: アベイラビリティゾーンの指定は不要)
• 期間(1年 or 3年)
http://aws.amazon.com/jp/elasticache/pricing/
http://aws.amazon.com/jp/elasticache/reserved-cache-nodes/
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 26. Simple Monthly Calculator
! Webフォームで概算費用を試算できます
§ http://calculator.s3.amazonaws.com/calc5.html?lng=ja_JP
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 27. AWS無料料試⽤用枠
! AWSでは、無料試用枠を用意しています
• http://aws.amazon.com/jp/free/
! ElastiCache も対応しています
• http://aws.amazon.com/jp/elasticache/free/
• 1年間、cache.t1.micro を 750時間/月 まで無料で利用可能です
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 28. アジェンダ
!
!
!
!
!
!
メモリキャッシュとは
Amazon ElastiCacheの概要
ElastiCache for Memcached
ElastiCache for Redis
ユースケース
まとめ
28
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 29. Memcachedとは
! インメモリ key-value ストアキャッシュサーバ
§ 2003年にDanga Interactiveが開発(BSDライセンス)
§ ブログサービス「Live Journal」の負荷対策用に作られたもの
§ 多くのサイトで採用 (YouTube, Wikipedia, mixi, etc. )
! 特徴
§ KVSのデファクトスタンダードプロトコル
• Key-valueのシンプルなデータ構造
• Telnetでも操作可能
§ 主要機能のみのシンプルな機能
• アクセス制御などのセキュリティ機能無し
• マスタノード、シャーディング、レプリケーションなどの機構無し
• データ削除は明示的、期限、LRUの3方式
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 30. Amazon ElastiCache for memcached
! 特徴
• 対応バージョン 1.4.5、1.4.14 (2013.10.30現在)
• memcached プロトコル準拠
• Cache Clusterという論論理理グループに、Cache Nodeを複数台起動
! 注意
• 複数のアベイラビリティゾーンにまたがった Cache Clusterは作れな
い。ゾーン毎に Cache Clusterを⽤用意する
CacheCluster A
Availability Zone - a
CacheCluster B
Availability Zone - b
30
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 31. Auto Discovery for memcached
! 従来のクライアント側の設定
•
Cache Clusterの全エンドポイントを接続先として設定する。
! Auto Discoveryクライアント(Java, PHP)
•
Cache ClusterのConfiguration Endpointを接続先として設定すると、全エンドポイントを自動
取得・設定し、接続する
! 注意
• Configuration Endpointは、Cache Clusterの ロードバランサー( Proxy) ではなく、
あくまでもメタデータを取得するEndpointとなる
CacheCluster
App
通常のクライアントライブラリ
xxx.0001.apne1.cache.amazonaws.com
App
Auto Discovery クライアントライブラリ
xxx.0002.apne1.cache.amazonaws.com
Configuration Endpoint
xxx.cfg.apne1.cache.amazonaws.com
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.html
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 32. CloudWatchによるmemcached の監視
! 監視項目
• http://docs.aws.amazon.com/AmazonElastiCache/latest/
UserGuide/CacheMetrics.Memcached.html
! 主に監視する項目
•
•
•
•
•
CPUUtilization (CPU使用率)
Evictions ( キャッシュメモリ不足によるキャッシュアウト発生回数)
SwapUsage
CurrConnections
http://docs.aws.amazon.com/AmazonElastiCache/latest/
UserGuide/CacheMetrics.WhichShouldIMonitor.html
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 33. アジェンダ
!
!
!
!
!
!
メモリキャッシュとは
Amazon ElastiCacheの概要
ElastiCache for Memcached
ElastiCache for Redis
ユースケース
まとめ
33
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 34. Redisとは?
! In-‐‑‒memory Key-‐‑‒Value Store
! ⾼高機能なデータ構造、データ操作
• List, Set, Sorted Set, Hash
! 永続化機構
• Snapshot, Append only File
! 冗⻑⾧長化機構
• Replication
! Pub/Sub機能
! Lua scripting
http://redis.io/
34
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 36. 嬉しい機能
Pub/Sub
• チャンネル / パターン
• メッセージング
subscribe
deliver
msg
Client 1
Client 2
msg
publishe
subscribe
Channels / Patterns
36
deliver
Client 3
msg
http://redis.io/topics/pubsub
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 37. ElastiCache for Redis
! 特徴
•
•
•
•
対応バージョン: 2.6.13 (2013.10.30現在)
Replication構成 も数クリックで構築可能
S3上のスナップショット(RDB)プリロード機能
Redisの特徴をほぼサポート
• Lua Scripting
• Pub/Sub
• Append Only File
! 対応しない機能
• CONFIG, SLAVEOFなど一部コマンドのみ無効
• パスワード (アクセス制御はセキュリティグループにて実施)
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 38. リードレプリカ (Replication)
! 以下の用途に利用可能
• 耐障害性向上(ただし、非同期レプリケーション)
• Read性能のスケーリング
! 構成
• Replication Group内に、マスター1台、レプリカ 最大5台
• Replica of Replica は未対応
Replication Group
CacheCluster
CacheCluster
Availability Zone - a
CacheCluster
Availability Zone - b
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Replication.html
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/ManagingReplication.html
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 41. ノード障害時の挙動と影響
リードレプリカあり
リードレプリカなし
障害
プライマリ障害
ノード障害
挙動
1. キャッシュイベントをSNSで通
1. キャッシュイベントをSNSで通
知を受取る
知を受取る
2. 再起動を試みる
2. 新しいノードを立ち上げ
3. 再起動失敗した場合手動FOが 3. DNS切替
必要
4. FO後プライマリDNS自動切替
影響
• FO完了まで書込不可
• FO中一定の時間(秒単位)RR
読込不可
キャッシュデータロスト
対策
• SNS通知を設定する
• クライント/アプリでエラーハンド
リング(retry, DBから取得など)
• SNS通知を設定する
• キャッシュ喪失時の対策も織り
込む
http://aws.amazon.com/jp/elasticache/faqs/#rf7
http://aws.amazon.com/jp/elasticache/faqs/#rf8
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 42. Sentinel vs. ElastiCache(Redis)
Redis Sentinel
• Redis本家のHAソリューション
Sentinel
ElastiCache
△
△
(自動昇格、endpoint
変更あり)
(手動昇格、endpoint
変更なし)
モニタリング
通知(アラート)
フェールオーバー
アプリ改修不要
管理不要
http://redis.io/topics/sentinel
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 43. RDBデータのプリロード
! 既存のRedisからのデータ移行に
• 既存のRedisで取得したRDBファイルをS3に保存
• キャッシュノード起動時に S3上のRDBファイルを読み込み
! 注意点
• RDBファイルのバージョン互換性を確認
• 保存したS3に対して、ElastiCacheが参照可能なパーミッションが必要
• キャッシュノードタイプがサポートするメモリサイズを超えるRDBは読み込み不可。
(起動時にエラーが発生)
Redis
EC2
RDB
copy
S3
ElastiCache
for
Redis
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/
ManagingCacheClusters.html#ManagingCacheClusters.SeedingRedis
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 45. プリロードの応用: バックアップ&リストア
• EC2上のRedisをslaveとして マスタに接続可能
• EC2上のRedis slave側でRDBファイルをS3へバックアップしてお
くことで、クラスタ起動時にS3からプリロード可能
slaveof
Redis
restore
RDB
copy
EC2
S3
http://redis.io/topics/persistence
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/
ManagingCacheClusters.html#ManagingCacheClusters.RedisSnapshots
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 46. Append-Only Files(AOF)について
! AOFとは
• 受信した全コマンド(操作)をローカルストレージ上のAOFに追記
• キャッシュノードreboot時にキャッシュデータの復元が可能
• メンテナンス時のreboot時にデータを保持可能
! デフォルトでは off
• パラメータグループで appendonly をyesに変更し有効化
• cache.t1.microは未対応( appendonly=yesでも無視される)
! 注意点
• ノード障害によるノード入れ替えが発生した場合はAOFが喪失する
• データ保全のためには最低1台のリードレプリカ構成を推奨
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/
CacheParameterGroups.Redis.html#CacheParameterGroups.Redis.AOF
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 47. CloudWatchによるRedis の監視
! 主に監視する項目
•
•
•
•
CPUUtilization (CPU使用率)
Evictions ( キャッシュメモリ不足によるキャッシュアウト発生回数)
CurrConnections
Replica Lag ( レプリケーション遅延)
! CPU 使用率を監視する際の注意点
•
•
•
•
Redisは シングルスレッドなので、1コアで動作
cache.m1.xlarge(4コア)だと、 25% (100% / 4) が最大値となる
Alert設定時には、上記点に注意する
http://docs.aws.amazon.com/AmazonElastiCache/latest/
UserGuide/CacheMetrics.WhichShouldIMonitor.html
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/CacheMetrics.html
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 48. アジェンダ
!
!
!
!
!
!
メモリキャッシュとは
Amazon ElastiCacheの概要
ElastiCache for Memcached
ElastiCache for Redis
ユースケース
まとめ
48
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 49. ユースケース
! memcached , redis
• データキャッシュ
• セッションストア
! redis
•
•
•
•
•
分散カウンター (atomic counter)
リアルタイム・メトリック (bitmaps)
キュー (lists)
メッセージング (pub/sub)
リーダーボード,スコアランキング (sorted sets)
49
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 50. ブロードキャスト
リアルタイム位置ゲーム
(broadcast
with
Redis
pub/sub)
*Image from:
https://geoloqi.com/blog/2011/09/building-a-real-time-location-based-urban-geofencing-game-with-socket-io-redisnode-js-and-sinatra-synchrony/
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 52. キャッシュのクラスタ化について
! 単一キャッシュノード構成の課題
• 障害時のデータ喪失による影響は少ない(はず)
§ ただしDBが過負荷になり、システムスローダウンやダウンも
§ キャッシュ容量増強のためにはスケールアップ(容易ではない)
App
RDBMS
キャッシュ
App
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 53. キャッシュのクラスタ化(Consistent Hashing)
! Consistent Hashingの特徴
•
§
§
§
Appサーバ側でConsistent Hashingアルゴリズムで振り分ける
ノード障害時のキャッシュ喪失が限定的
ノード追加で総キャッシュ容量を増やしやすい
ノード数変更時のリバランスコストが限定的
APPサーバ
キャッシュ
ライブラリ
CHアルゴリズム
ノードリスト
キャッシュ
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 54. クラスタリングの方法
! クライアントライブラリにて
• PHPなどで使うlibmemcachedは標準でdistribution アルゴリズム実装済み
!
Twemproxy
•
•
•
•
Twitter社が開発したMemcached/Redis⽤用のproxy
複数サーバーのシャーディング (consistent hashing)
キャッシュサーバーの接続管理理
⼀一部未サポートのコマンドもあり
! 参考
§ Consistent hashing - Wikipedia, the free encyclopedia
§ http://en.wikipedia.org/wiki/Consistent_hashing
§ memcachedを知り尽くす:第4回 memcachedの分散アルゴリズム|
gihyo.jp … 技術評論社
§ http://gihyo.jp/dev/feature/01/memcached/0004?page=3
§ Partitioning: how to split data among multiple Redis instances.
§ http://redis.io/topics/partitioning
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 56. アジェンダ
!
!
!
!
!
!
メモリキャッシュとは
Amazon ElastiCacheの概要
ElastiCache for Memcached
ElastiCache for Redis
ユースケース
まとめ
56
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 57. Amazon ElastiCache の利利点
! 構築・運⽤用が⾮非常に容易易
• Management Console やAPIからクラスタの作成が可能
• 性能監視、⾃自動復復旧機能、⾼高可⽤用性機能、パッチ機能
• レプリケーション(redis)
! セキュリティ
• セキュリティグループによるアクセス制御
• VPC内部でも利利⽤用可能
57
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 58. 参考資料
! Amazon ElastiCache 概要
• http://aws.amazon.com/jp/elasticache/
! 料金
• http://aws.amazon.com/jp/elasticache/pricing/
• http://aws.amazon.com/jp/elasticache/reserved-cache-nodes/
! FAQ
• http://aws.amazon.com/jp/elasticache/faqs/
! ドキュメント
• http://aws.amazon.com/jp/documentation/elasticache/
! Amazon ElastiCache フォーラム
• https://forums.aws.amazon.com/forum.jspa?forumID=127
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 59. APPENDIX
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 60. Appendix: Redis で制限されているコマンド
! 以下のコマンドは実行不可(unknown command扱い)
•
•
•
•
設定系 (config, slaveof)
データ制御系 ( save, bgsave, bgrewriteof, migrate)
プロセス制御系( shutdown)
debug
! 参考
• http://redis.io/commands
• http://docs.aws.amazon.com/AmazonElastiCache/latest/
UserGuide/ClientConfig.html#ClientConfig.RestrictedCommands
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 61. Appendix: Redis で変更不可パラメータ
! 以下のパラメータは変更不可
•
•
•
•
•
activerehashing=Yes
databases=16
lua-time-limit
maxclients
maxmemory ( maxmemory-policyは変更可能)
! 参考
• http://redis.io/topics/config
• http://docs.aws.amazon.com/AmazonElastiCache/latest/
UserGuide/CacheParameterGroups.Redis.html
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 62. Appendix: Scale-up vs. Scale-out
Scale-up
Scale-out
性能アップ
運用しやすい
開発しやすい
△
Library/proxyが必要
障害時影響が少ない
△
RedisはFOで影響を抑える
スケール
△
ノード一台のメモリ上限(68GB)まで ノード追加でスケール
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 63. Appendix: メモリGB単価
m2シリーズは
メモリ単価が安い
メモリ単価
0.16
0.14
Case Study
• 4GBが必要なら
• m1.large
• 32GBが必要なら
• m2.2xlarge (scale-‐‑‒up)
• m2.xlarge X 2 (Hybrid)
• m1.large X 6 (scale-‐‑‒out)
0.12
0.1
0.08
0.06
$/h/GB
0.04
0.02
0
*Y軸: 1GBメモリの単価
*memcachedの max_cache_memory を基準で計算
Redis も同じトレンド
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 64. Appendix: コストパフォーマンス
m1.medium⼀一台を
1時間使った場合:$0.206
Cost / Performance
のいいタイプ
• t1.micro
• m1.small
• m1.medium
• m1.large
• m2.xlarge
Cost/Performance
1.2
1
0.8
0.6
0.4
0.2
相対CP
0
*Y軸: m2.4xlargeのコストパフォーマンスを1とした場合の
相対値
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.