Data Stream Processing and Analysis on AWS #awscasual

Kenta Suzuki
Kenta SuzukiEngineer at VOYAGE GROUP
Data Stream Processing and
Analysis on AWS:
Fluentd, Elasticsearch, DynamoDB,
EMR and Amazon Kinesis
AWS Casual Talks #2
@suzu_v
すずけん, @suzu_v
VOYAGE GROUPで働いてます
その中のadingoという会社でR&Dをしてます
http://suzuken.hatenablog.jp/
Data Stream Processing and Analysis on AWS #awscasual
アンケート
Amazon Kinesis
ユーザの方?
Fluentd使っている方?
Elasticsearchユーザの方?
DynamoDB使ってる方?
EMR使ってる方?
今日はログの解析基盤のアーキテクチャと
Kinesisの検証をしている話をします
Data
Sources
App.4
[Machine
Learning]
AWSEndpoint
App.1
[Aggregate &
De-Duplicate]
Data
Sources
Data
Sources
Data
Sources
App.2
[Metric
Extraction]
S3
DynamoDB
Redshift
App.3
[Sliding
Window
Analysis]
Data
Sources
Availability
Zone
Shard 1
Shard 2
Shard N
Availability
Zone
Availability
Zone
Amazon Kinesis
Managed Service for Real-Time Processing of Big Data
http://www.slideshare.net/AmazonWebServices/amazon-kinesis-realtime-streaming-big-data-
processing-applications-bdt311-aws-reinvent-2013
Kinesis Architecture
log
log
log
log
log
log
log
log
log
log
log
log
Amazon
Kinesis
Kinesis
Application
stream
Data Record
shard
Partition key
DataStore
Kinesis Architecture
log
log
log
log
log
log
log
log
log
log
log
log
Amazon
Kinesis
Kinesis
Application
stream
Data Record
shard
Partition key
DataStore
site_id
2014/04/18 site_id: 1 user_id: 1
count by site 1~100
count by site 101~200
count by site 201~300
top ranking
Kinesis Architecture
log
log
log
log
log
log
log
log
log
log
log
log
Amazon
Kinesis
Kinesis
Application
stream
Data Record
shard
Partition key
DataStore
user_id
2014/04/18 item_id: 1 user_id: 1
coefficient: item visited by user 1-10000
update matrix
(in near real time)
coefficient: item visited by user 10001-20000
coefficient: item visited by user 20001-30000
Out System
システム概要
広告ログを分析するための基盤
アドホックな分析&定常分析
ターゲティングにも使う
カジュアルなシステム要件
複数サービスのログをひたすら取り込む。
過去ログをひたすら取り込み、快適に分析できる
ようにする。hot / cold dataの分析を両立する。
ターゲティングはベストエフォート。
2012 mid.ELB
EC2
EC2 EC2
EC2
request
S3 MongoDB
Cluster
(EC2)
EMR
ELB
EC2
EC2 EC2
EC2
http api
crontab
hourly
daily
php + apache
php + apache
Arch. #1 / 2012 mid.
Cons
not real-time
MongoDBのwriteによる負荷
が高い
MongoDBの集計処理が重い
MapReduceジョブを回さな
いと分析ができない
Pros
MongoDBの柔軟性
データの受け入れが
安定
2014 earlyELB
EC2
EC2 EC2
EC2
request
EC2
S3
DynamoDB
EMR ELB
EC2
EC2 EC2
EC2
http api
Elastic
search
Growth
Forecast
fluentd
fluentd
(aggregator)
exec_filter
out_elasticsearch
out_dynamodb
servlet (scala)
dynamic-dynamo
ある日のトラフィックパターンと自動スケーリングの様子
sebdah/dynamic-dynamodb
https://github.com/sebdah/dynamic-dynamodb
Arch. #2 / 2014 early
Cons
Fluentdが便利すぎるがために、aggregatorにい
ろいろやらせすぎてる。
Fluentdのバッファが詰まって死ぬ、とか
ある困る。
preノードを追加してストリームを逃がす
こともしているが、fluentの設定が複雑化
する
ストリーム処理をより柔軟に、多様に、疎結合
に扱いたい
Elasticsearchに長期間の大量データを集計させ
るとそれなりにパワーが必要
Pros
Elasticsearch + Kibanaにより、エンジニア以
外のメンバーもhotなデータのドリルダウン
を行えるように
DynamoDB導入によりwrite / readともに安定
dynamic-dynamodbを採用。throughput
を自動調節するように。
EMR上のHiveから、s3にあるログとDynamoDB
にある分析済みデータを組み合わせたクエ
リが可能に
準リアルタイムなターゲティングが可能に
ここから検証中の話
Next ?ELB
EC2
EC2 EC2
EC2
request
EC2
S3
DynamoDB
EMR ELB
EC2
EC2 EC2
EC2
http api
Elastic
search
Growth
Forecast
Amazon Kinesis
Kinesis App.
Amazon Kinesisの検証項目
求めているスループットはでるか?
どれくらいの負荷で書き込めるか?
書き込み失敗時にどのような挙動になるか?ハン
ドリングできるか?
KCL(Kinesis Client Library)での開発は楽か?
ざっくりとした使用感 - producer
aggregatorを用意してwriteするのではなく、logの発生源から直接書くほうが
throughputを出しやすい。ただし、1レコードずつ書き込まなければならないた
め、fluentdのout pluginではthroughputが出しづらい。
1 shard 1000 put request / sec. の制限がある。大きなオブジェクトを書き込まない
限り、byte制限よりこちらに引っかかるケースのほうが多い。とはいえ、シャー
ドの追加は簡単なので、大きな問題にはならない。緩和申請は計画的に。
書き込み時の負荷を意識する必要がないので楽。とりあえず入れておけば、
Consumer側でよしなにできる。
Kinesis内に24時間残ってくれるのは便利。ただし、Kinesisへの書き込み失敗時の
ハンドリングをする必要はある。
ざっくりとした使用感 - consumer
DynamoDBが活躍する。Kinesis ApplicationからDynamoDBへの書き込みは楽。Scalingも問題な
い。
readは1 shard 5 transaction / sec.の制限がある。なので1transactionである程度まとめてデータ
を取得する作りにする必要がある。そもそも足りないならshardを増やす。
失敗時のretryのため、Kinesis Applicationの各Workerで各Shardをどこまで処理したのかを
Checkpointとして記録しておく必要がある。KCL(Kinesis Client Library)使うとこのへんはよしな
にDynamoDBで管理するようにしてくれる。
EMRからもConnectorがあるので簡単に扱える。
EMR上のSpark Streamingから扱うのは手軽で良い。EMRでSparkクラスタを立てられるので、
aliveにしてストリームに対してwindowクエリを流し続けるのは手軽なユースケースになりそ
う。
Kinesisへの移行で発生する作業
fluentdのexec_filterとかexecとかでやっていたことをKinesis
Applicationに置き換える必要がある
パーティションキーの考慮、consumeが失敗した場合のケア
fluentdでいうaggregatorノードを作るのではなくて、ログを出す
各サーバから直接Kinesisに転送するような作りにしたほうが良さ
そう
1行のログごとの書き込みなので、1ノードからのKinesisへの
書き込みスループットが現段階ではあまりでない。
Kinesis, こうなったら良い
Kinesisのメトリクスも1min.ごとに見たい
DynamoDB同様、batchWriteが欲しい
ap-northeast-1! 東京リージョン!
カジュアルなまとめ
Amazon Kinesisもっと使いましょう
東京リージョン待ってます
参考資料
Kinesis関連
Amazon Web Services ブログ: 【AWS発表】KinesisとElastic MapReduceを使ってストリーミングデータ
を処理する
http://aws.typepad.com/aws_japan/2014/03/process-streaming-data-with-kinesis-and-elastic-
mapreduce.html
Amazon Kinesis: Real-time Streaming Big data Processing Applications (BDT311) | AWS re:Invent 2013
http://www.slideshare.net/AmazonWebServices/amazon-kinesis-realtime-streaming-big-data-
processing-applications-bdt311-aws-reinvent-2013
https://www.youtube.com/watch?v=AXAaCG2QUkE
re:Invent 2013でのKinesisの紹介スライド及びビデオです。KeynoteでのKinesisのデモに利用さ
れていたTwitterのhashtagをcountするデモの構築方法についてまとまっています。
ShardのマネジメントをDynamoDBを利用して行っているところなど、わかりやすく説明され
ています。
Kinesis関連
Developing Record Consumer Applications - Amazon Kinesis
http://docs.aws.amazon.com/kinesis/latest/dev/kinesis-record-processor-
app.html
Kinesis Client Libraryを使ったConsumerの作成方法についてまとまっていま
す
Tutorial: Analyzing Amazon Kinesis Streams with Amazon EMR and Hive - Amazon
Elastic MapReduce
http://docs.aws.amazon.com/ElasticMapReduce/latest/DeveloperGuide/query-
kinesis.html
Kinesis StreamをEMR上のHiveで取り扱う方法について説明されています。
Log4jAppender for Kinesis
Download Log4J Appender for Amazon Kinesis Sample
Application, Sample Credentials File, and Sample Log
File - Amazon Elastic MapReduce
http://docs.aws.amazon.com/ElasticMapReduce/
latest/DeveloperGuide/kinesis-pig-publisher.html
てっとりばやくKinesisに書き込みたいならこれが
いいです
Kinesis with EMR
Spark Streaming
http://www.cs.berkeley.edu/~marmbrus/sparkdocs/_site/streaming-
programming-guide.html
cold dataとhot dataを組み合わせてwindowしたり
例)特定クライアントのキャンペーンにおける5分毎のクリック数
Run Spark and Shark on Amazon Elastic MapReduce : Articles & Tutorials :
Amazon Web Services
https://aws.amazon.com/articles/Elastic-MapReduce/4926593393724923
credit
扉絵
https://www.flickr.com/photos/
65220434@N02/13645528234/sizes/l
fluent-plugin-elasticsearch
uken/fluent-plugin-elasticsearch
https://github.com/uken/fluent-plugin-
elasticsearch
hostsオプションおすすめ
Kibana向けにオプション作れるの便利
chunkサイズはES側の設定と合わせておくと良い
fluent-plugin-kinesis
imaifactory/fluent-plugin-kinesis
https://github.com/imaifactory/fluent-plugin-kinesis
まだrubygemsには上がってない
fluentのchunkと、Kinesisのwrite APIの相性が…
throughput出すならbatchで書き込めないとつらそ
う
1 of 38

Recommended

CloudTrail でログとれ〜る by
CloudTrail でログとれ〜るCloudTrail でログとれ〜る
CloudTrail でログとれ〜るHokuto Hoshi
12.1K views63 slides
AWS Casual2 LT by
AWS Casual2 LTAWS Casual2 LT
AWS Casual2 LTTomohiro Ikeda
10.2K views45 slides
20140418 aws-casual-network by
20140418 aws-casual-network20140418 aws-casual-network
20140418 aws-casual-networkYasuhiro Araki, Ph.D
10.4K views28 slides
5分でできる ebfly by
5分でできる ebfly5分でできる ebfly
5分でできる ebflyKazuyuki Honda
6.5K views15 slides
Amazon Kinesis: Real-time Streaming Big data Processing Applications (BDT311)... by
Amazon Kinesis: Real-time Streaming Big data Processing Applications (BDT311)...Amazon Kinesis: Real-time Streaming Big data Processing Applications (BDT311)...
Amazon Kinesis: Real-time Streaming Big data Processing Applications (BDT311)...Amazon Web Services
15.3K views48 slides
Spot Instance + Spark + MLlibで実現する簡単低コスト機械学習 by
Spot Instance + Spark + MLlibで実現する簡単低コスト機械学習Spot Instance + Spark + MLlibで実現する簡単低コスト機械学習
Spot Instance + Spark + MLlibで実現する簡単低コスト機械学習Katsushi Yamashita
12.2K views20 slides

More Related Content

More from Kenta Suzuki

AWS SDK for Go in #jawsmeguro by
AWS SDK for Go in #jawsmeguroAWS SDK for Go in #jawsmeguro
AWS SDK for Go in #jawsmeguroKenta Suzuki
4.7K views20 slides
Data Engineering at VOYAGE GROUP #jawsdays by
Data Engineering at VOYAGE GROUP #jawsdaysData Engineering at VOYAGE GROUP #jawsdays
Data Engineering at VOYAGE GROUP #jawsdaysKenta Suzuki
9.6K views78 slides
fluentd設定行数とシステム複雑性のカジュアルな話 by
fluentd設定行数とシステム複雑性のカジュアルな話fluentd設定行数とシステム複雑性のカジュアルな話
fluentd設定行数とシステム複雑性のカジュアルな話Kenta Suzuki
2.7K views21 slides
サービス改善はログデータ分析から by
サービス改善はログデータ分析からサービス改善はログデータ分析から
サービス改善はログデータ分析からKenta Suzuki
18.9K views41 slides
DMPの仕組み by
DMPの仕組みDMPの仕組み
DMPの仕組みKenta Suzuki
27.6K views24 slides
web広告輪講 #5 by
web広告輪講 #5web広告輪講 #5
web広告輪講 #5Kenta Suzuki
1.4K views22 slides

More from Kenta Suzuki(9)

AWS SDK for Go in #jawsmeguro by Kenta Suzuki
AWS SDK for Go in #jawsmeguroAWS SDK for Go in #jawsmeguro
AWS SDK for Go in #jawsmeguro
Kenta Suzuki4.7K views
Data Engineering at VOYAGE GROUP #jawsdays by Kenta Suzuki
Data Engineering at VOYAGE GROUP #jawsdaysData Engineering at VOYAGE GROUP #jawsdays
Data Engineering at VOYAGE GROUP #jawsdays
Kenta Suzuki9.6K views
fluentd設定行数とシステム複雑性のカジュアルな話 by Kenta Suzuki
fluentd設定行数とシステム複雑性のカジュアルな話fluentd設定行数とシステム複雑性のカジュアルな話
fluentd設定行数とシステム複雑性のカジュアルな話
Kenta Suzuki2.7K views
サービス改善はログデータ分析から by Kenta Suzuki
サービス改善はログデータ分析からサービス改善はログデータ分析から
サービス改善はログデータ分析から
Kenta Suzuki18.9K views
DMPの仕組み by Kenta Suzuki
DMPの仕組みDMPの仕組み
DMPの仕組み
Kenta Suzuki27.6K views
web広告輪講 #5 by Kenta Suzuki
web広告輪講 #5web広告輪講 #5
web広告輪講 #5
Kenta Suzuki1.4K views
Head First Ad Technology and DMP by Kenta Suzuki
Head First Ad Technology and DMPHead First Ad Technology and DMP
Head First Ad Technology and DMP
Kenta Suzuki9.4K views
データとは何か by Kenta Suzuki
データとは何かデータとは何か
データとは何か
Kenta Suzuki3.7K views
Jenkinsとhadoopを利用した継続的データ解析環境の構築 by Kenta Suzuki
Jenkinsとhadoopを利用した継続的データ解析環境の構築Jenkinsとhadoopを利用した継続的データ解析環境の構築
Jenkinsとhadoopを利用した継続的データ解析環境の構築
Kenta Suzuki6.3K views

Recently uploaded

robotics42.pptx by
robotics42.pptxrobotics42.pptx
robotics42.pptxNatsutani Minoru
188 views18 slides
SSH超入門 by
SSH超入門SSH超入門
SSH超入門Toru Miyahara
207 views21 slides
図解で理解するvetKD by
図解で理解するvetKD図解で理解するvetKD
図解で理解するvetKDryoo toku
85 views22 slides
3Dプリンタでロボット作るよ#1_黎明編 by
3Dプリンタでロボット作るよ#1_黎明編3Dプリンタでロボット作るよ#1_黎明編
3Dプリンタでロボット作るよ#1_黎明編Yoshihiro Shibata
20 views7 slides
Najah Matsuo Self Introduction by
Najah Matsuo Self IntroductionNajah Matsuo Self Introduction
Najah Matsuo Self IntroductionNajahMatsuo
7 views29 slides
lt.pptx by
lt.pptxlt.pptx
lt.pptxtomochamarika
69 views13 slides

Recently uploaded(10)

図解で理解するvetKD by ryoo toku
図解で理解するvetKD図解で理解するvetKD
図解で理解するvetKD
ryoo toku85 views
3Dプリンタでロボット作るよ#1_黎明編 by Yoshihiro Shibata
3Dプリンタでロボット作るよ#1_黎明編3Dプリンタでロボット作るよ#1_黎明編
3Dプリンタでロボット作るよ#1_黎明編
Najah Matsuo Self Introduction by NajahMatsuo
Najah Matsuo Self IntroductionNajah Matsuo Self Introduction
Najah Matsuo Self Introduction
NajahMatsuo7 views
AIで始めるRustプログラミング #SolDevHub by K Kinzal
AIで始めるRustプログラミング #SolDevHubAIで始めるRustプログラミング #SolDevHub
AIで始めるRustプログラミング #SolDevHub
K Kinzal21 views
how query cost affects search behavior translated in JP by Tobioka Ken
how query cost affects search behavior translated in JPhow query cost affects search behavior translated in JP
how query cost affects search behavior translated in JP
Tobioka Ken9 views
onewedge_companyguide1 by ONEWEDGE1
onewedge_companyguide1onewedge_companyguide1
onewedge_companyguide1
ONEWEDGE17 views

Data Stream Processing and Analysis on AWS #awscasual