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
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
870
The Rise of LLMOps
asei
6
1.3k
Terraform Stacks入門 #HashiTalks
msato
0
350
元旅行会社の情シス部員が教えるおすすめなre:Inventへの行き方 / What is the most efficient way to re:Invent
naospon
2
340
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
6
670
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
0
110
ハイパーパラメータチューニングって何をしているの
toridori_dev
0
140
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.3k
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
For a Future-Friendly Web
brad_frost
175
9.4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Side Projects
sachag
452
42k
Embracing the Ebb and Flow
colly
84
4.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
4 Signs Your Business is Dying
shpigford
180
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
A Tale of Four Properties
chriscoyier
156
23k
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