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.8k
カジュアルにリアクティブウェブを実現している話
nashibao
1
5.4k
fishシェルからのエトセトラ - nanapi勉強会 vol2
nashibao
1
480
Other Decks in Technology
See All in Technology
AWS re:Invent 2024 recap in 20min / JAWSUG 千葉 2025.1.14
shimy
1
100
20250116_JAWS_Osaka
takuyay0ne
2
200
AWS Community Builderのススメ - みんなもCommunity Builderに応募しよう! -
smt7174
0
180
I could be Wrong!! - Learning from Agile Experts
kawaguti
PRO
8
3.4k
DMMブックスへのTipKit導入
ttyi2
1
110
re:Invent 2024のふりかえり
beli68
0
110
Docker Desktop で Docker を始めよう
zembutsu
PRO
0
170
AWS re:Invent 2024 re:Cap Taipei (for Developer): New Launches that facilitate Developer Workflow and Continuous Innovation
dwchiang
0
160
完全自律型AIエージェントとAgentic Workflow〜ワークフロー構築という現実解
pharma_x_tech
0
350
コロプラのオンボーディングを採用から語りたい
colopl
5
1.2k
自社 200 記事を元に整理した読みやすいテックブログを書くための Tips 集
masakihirose
2
330
Godot Engineについて調べてみた
unsoluble_sugar
0
400
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
5
210
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
GraphQLとの向き合い方2022年版
quramy
44
13k
Fireside Chat
paigeccino
34
3.1k
How GitHub (no longer) Works
holman
312
140k
Done Done
chrislema
182
16k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Site-Speed That Sticks
csswizardry
2
270
How to train your dragon (web standard)
notwaldorf
89
5.8k
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