Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Amazon Kinesisでストリーム解析 - Node学園12時限目
Search
nashibao
April 24, 2014
Technology
4
3.9k
Amazon Kinesisでストリーム解析 - Node学園12時限目
Node学園12時限目で話します.
Amazon Kinesisをストリーム解析に使えるか検証した時の話です.
http://plaid.co.jp
nashibao
April 24, 2014
Tweet
Share
More Decks by nashibao
See All by nashibao
ちゃんと使えるBotについて考える
nashibao
0
2.2k
PySparkを使った レコメンドアルゴリズムの改良
nashibao
1
5.7k
カジュアルにリアクティブウェブを実現している話
nashibao
1
5.4k
fishシェルからのエトセトラ - nanapi勉強会 vol2
nashibao
1
470
Other Decks in Technology
See All in Technology
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
230
GitHub Copilot のテクニック集/GitHub Copilot Techniques
rayuron
37
15k
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
2
400
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
270
Google Cloud で始める Cloud Run 〜AWSとの比較と実例デモで解説〜
risatube
PRO
0
110
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
270
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
360
非機能品質を作り込むための実践アーキテクチャ
knih
5
1.5k
DUSt3R, MASt3R, MASt3R-SfM にみる3D基盤モデル
spatial_ai_network
2
190
ハイテク休憩
sat
PRO
2
170
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Unsuck your backbone
ammeep
669
57k
4 Signs Your Business is Dying
shpigford
181
21k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
98
A Tale of Four Properties
chriscoyier
157
23k
Fireside Chat
paigeccino
34
3.1k
Adopting Sorbet at Scale
ufuk
73
9.1k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Building Applications with DynamoDB
mza
91
6.1k
KATA
mclloyd
29
14k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
A designer walks into a library…
pauljervisheath
204
24k
Transcript
Amazon KinesisͰ ετϦʔϜղੳ (ג)ϓϨΠυ @nashibao
0. Who are you?
@nashibaoͱ͍͍·͢ ࣲࢁथ తࢄܕػցֶशతΤϯδχΞ(31) ! ~201208: େֶͱ͔Ͱʑͱ͢ΔɽMapReduceͱߦྻղ͕ɽ 201209: Node.jsʹ֮ΊΔ 201304: ݩָఱ(31)ͱىۀ
σʔλղੳ&CRMαʔϏε 201309: ത࢜υϩοϓΞτ
(ג)ϓϨΠυͱ͍͍·͢ http://plaid.co.jp EC͚ͷղੳ&CRMαʔϏεΛεςϧε։ൃதɽ ! ݱࡏ։ൃͨͬͨ2ਓ(t-nakamura)ͳͷͰɺ ԠืΛຊʹ͓͓ͪͯ͠Γ·͢ʂ ෲյ͢·Ͱ͕৯͑ΔձࣾʂͦΕ͕ϓϨΠυʂ ܴձγϡϥείͰ͢ʂ
Amazon KinesisΛετϦʔϜ ղੳʹ͑Δ͔ݕূ͓ͨ͠
1. Kinesisͱʁ 2. Node.js͔ΒKinesisΛ͏ 3. ύϑΥʔϚϯεݕূ 4. ײ
1. Kinesisͱʁ
Amazon Kinesis
“a fully managed service for real-time processing of streaming data
at massive scale.” ͲͰ͔͍σʔλ͔Β ϦΞϧλΠϜॲཧ͕ग़དྷΔ ϑϧϚωʔδυͳαʔϏε
5JCTF 5JCTF 5JCTF -# -# -# 2TQFWEGT -KPGUKU#RRNKECVKQPU 5VTGCO 2TQFWEGT
2TQFWEGT 2TQFWEGT 2TQFWEGT 哋┮䠉㏰ا揉ⓧ
5JCTF 5JCTF 5JCTF -# -# -# WEGT -KPGUKU#RRNKECVKQPU 5VTGCO WEGT
WEGT WEGT EGT ϑϧϚωʔδυͳ෦ ! • 24࣌ؒอ࣋ • ࠶औಘՄʢex: Τϥʔ࣌ʣ • 1000tps/shard put • 5tps/shard get
5JCTF 5JCTF 5JCTF -# -# -# WEGT -KPGUKU#RRNKECVKQPU 5VTGCO WEGT
WEGT WEGT EGT ϑϧϚωʔδυͳ෦ ! • 24࣌ؒอ࣋ • ࠶औಘՄʢex: Τϥʔ࣌ʣ • 1000tps/shard put • 5tps/shard get • hashKey(ࣗ༝)ͰৼΓ͚
5JCTF 5JCTF 5JCTF -# -# -# WEGT -KPGUKU#RRNKECVKQPU 5VTGCO WEGT
WEGT WEGT EGT େྔʹॻ͖ࠐΜͰ ·ͱΊͯ औಘ͢ΔͨΊͷΩϡʔ? ॻ͖ࠐΈΛΩϟογϡ͢Δ ड͚ࡼͷΑ͏ͳΠϝʔδ
ෛՙूதͷड͚ࡼʹ Ͱ͖Δʁ
5KVG# 5KVG$ &$ &$ ! 5VTGCO #PCN[VKEU 5GOKDCVEJ/CR4GFWEG ! .QIIGT
Ý ݱঢ় YGDUQEMGV
5KVG# 5KVG$ &$ &$ ! 5VTGCO #PCN[VKEU 5GOKDCVEJ/CR4GFWEG ! .QIIGT
Ý ݱঢ় ෛՙ͕ूத͢Δͱ͘͞ͷେมʂ YGDUQEMGV
5KVG# 5KVG$ &$ &$ ! 5VTGCO #PCN[VKEU 5GOKDCVEJ/CR4GFWEG ! .QIIGT
Ý Kinesis? YGDUQEMGV
5KVG# 5KVG$ &$ ! 5VTGCO #PCN[VKEU 5GOKDCVEJ/CR4GFWEG Kinesis? -KPGUKU !
Ý YGDUQEMGV
2.Node.js͔Βѻ͏
plaidev/kinesis-wrapper.js # install npm install kinesis-wrapper.js # stream ϕʔε mhart/kinesis
! # ΫϥγΧϧͳͷ͕ཉ͍͠ͷɽɽ͔ͩΒॻ͍ͨͷɽɽ plaidev/kinesis-wrapper.js
plaidev/kinesis-wrapper.js # install npm install kinesis-wrapper.js # stream ϕʔε mhart/kinesis
! # bacon.js ϕʔε andyhorng/kinesis ! # ΫϥγΧϧͷ͕ཉ͍͠ͷɽɽ͔ͩΒॻ͍ͨͷɽɽ plaidev/kinesis-wrapper.js
1. putRecordͰ͛ࠐΉ var kinesis = require('..'); ! # ετϦʔϜͱͭͳ͛Δ var
stream = kinesis.stream('hoge'); ! # ‘key’MD5ͰϋογϡԽ͞ΕͯγϟʔυʹৼΓ͚ΒΕΔ stream.putRecord('key', {date: new Date()}, function(err, res){ console.log(err, res); });
2. getRecordsͰϙʔϦϯά var kinesis = require('..'); ! # ετϦʔϜͱͭͳ͛Δ var
stream = kinesis.stream('hoge'); ! # ϙʔϦϯάͯ͠औಘɽγϟʔυ͝ͱग़དྷ·͢ stream.getRecords(function(err, records){ console.log(new Date(), records[0].val.date); });
͍ͭͰʹ ಉظతʹฒྻԽ͢Δ • async.jsʁ • ͜Ε͔Βyieldʂ • node-thunkify • nashibao/co-gateѱ͘ͳ͍Αʂ
co-gateϞδϡʔϧ ैདྷͷίʔϧόοΫܗࣜͷؔΛͦͷ··ฒ ྻԽɾಉظతʹॻ͚Δ ICVG ECNNDCEM ECNNDCEM ECNNDCEM ECNNDCEM KP QWV
TGUWNVU
var co = require('co'); var Gate = require('co-gate'); ! co(function
*(){ ! var gate = new Gate(); ! async_function(gate.in()); ! var results = yield gate.out(); ! })(); co-gateϞδϡʔϧ
3. େྔʹ͛ࠐΉʢ࠶ʣ co(function *(){ var gate = new Gate(); !
for (var i = 0; i < 100; i++){ stream.putRecord('key', {date: new Date()}, gate.in()); } ! var res = yield gate.out(); }
4. ϙʔϦϯάʢ࠶ʣ co(function *(){ var gate = new Gate(); !
stream.getRecords(gate.in()); ! var records = yield gate.out(); })();
3. KinesisͷύϑΥʔϚϯε
ݕূڥɾ݅ • EC2(c3-4xlarge)1͔Β͛ͯݕূɽ • ΫϥΠΞϯτଆͷλΠϜελϯϓͰtpsΛܭଌ • 1~3shard • ৄ͘͠ɺ͏গ͠ݕূඞཁ
putRecord / shard UQTͱ͔ೖͬͨΓ͢Δɽɽ
put & getRecords UQTఔͰݻ·ͬͯऔಘͰ͖Δ
ࢥͬͨΑΓॻ͖ࠐΊΔɽͰ ͪΐͬͱ͍? • max3000~ tps/shard put • ॻ͖ࠐΈ͗͢Δͱ݁ہऔΓग़͢·Ͱʹ͔͔࣌ؒΔɽ • ݁ہ400~700tpsఔ·Ͱ͍͚Δ͜ͱ֬ೝ
• avg1sec get • ϙʔϦϯάࠐΈͰ͜ͷఔ • 200msҎʹฦͬͯ͘ΔΘ͚͡Όͳ͍ • ॻ͖ࠐΜͰऔΓग़͢·Ͱʹͳ͔ͥϥά͕͋ͬͨΓͳ͔ͬͨΓ
ײ • ϑϧϚωʔδυʁ • KAࣗͰཧɽγϟʔυʹϫʔΧʔͤΒΕͳ͍ͷ͔ɽɽ ! • ϦΞϧλΠϜʁ • ϙʔϦϯά
• औΓग़͢ͷʹϥά͕͚ͬ͜͏͋Δ ! • ύϑΥʔϚϯε • writeߴ͍ɽγϟʔυ૿͔ͤͳΓ͍͚ͦ͏
͋Γ͕ͱ͏͍͟͝·ͨ͠ɽ
http://plaid.co.jp