Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Amazon Kinesisでストリーム解析 - Node学園12時限目

nashibao
April 24, 2014

Amazon Kinesisでストリーム解析 - Node学園12時限目

Node学園12時限目で話します.
Amazon Kinesisをストリーム解析に使えるか検証した時の話です.
http://plaid.co.jp

nashibao

April 24, 2014
Tweet

More Decks by nashibao

Other Decks in Technology

Transcript

  1. “a fully managed service for real-time processing of streaming data

    at massive scale.” ͲͰ͔͍σʔλ͔Β ϦΞϧλΠϜॲཧ͕ग़དྷΔ ϑϧϚωʔδυͳαʔϏε
  2. 5JCTF 5JCTF 5JCTF -# -# -# 2TQFWEGT -KPGUKU#RRNKECVKQPU 5VTGCO 2TQFWEGT

    2TQFWEGT 2TQFWEGT 2TQFWEGT 哋┮؃䠉㏰׵ا揉ⓧ
  3. 5JCTF 5JCTF 5JCTF -# -# -# WEGT -KPGUKU#RRNKECVKQPU 5VTGCO WEGT

    WEGT WEGT EGT ϑϧϚωʔδυͳ෦෼ ! • 24࣌ؒอ࣋ • ࠶औಘՄʢex: Τϥʔ࣌ʣ • 1000tps/shard put • 5tps/shard get
  4. 5JCTF 5JCTF 5JCTF -# -# -# WEGT -KPGUKU#RRNKECVKQPU 5VTGCO WEGT

    WEGT WEGT EGT ϑϧϚωʔδυͳ෦෼ ! • 24࣌ؒอ࣋ • ࠶औಘՄʢex: Τϥʔ࣌ʣ • 1000tps/shard put • 5tps/shard get • hashKey(ࣗ༝)ͰৼΓ෼͚
  5. 5JCTF 5JCTF 5JCTF -# -# -# WEGT -KPGUKU#RRNKECVKQPU 5VTGCO WEGT

    WEGT WEGT EGT େྔʹॻ͖ࠐΜͰ ·ͱΊͯ औಘ͢ΔͨΊͷΩϡʔ? ॻ͖ࠐΈΛΩϟογϡ͢Δ ड͚ࡼͷΑ͏ͳΠϝʔδ
  6. 5KVG# 5KVG$ &$ &$ ! 5VTGCO #PCN[VKEU 5GOKDCVEJ/CR4GFWEG ! .QIIGT

    Ý ݱঢ় ෛՙ͕ूத͢Δͱ͞͹͘ͷେมʂ YGDUQEMGV
  7. plaidev/kinesis-wrapper.js # install npm install kinesis-wrapper.js # stream ϕʔε mhart/kinesis

    ! # ΫϥγΧϧͳͷ͕ཉ͍͠ͷɽɽ͔ͩΒॻ͍ͨͷɽɽ plaidev/kinesis-wrapper.js
  8. plaidev/kinesis-wrapper.js # install npm install kinesis-wrapper.js # stream ϕʔε mhart/kinesis

    ! # bacon.js ϕʔε andyhorng/kinesis ! # ΫϥγΧϧͷ͕ཉ͍͠ͷɽɽ͔ͩΒॻ͍ͨͷɽɽ plaidev/kinesis-wrapper.js
  9. 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); });
  10. 2. getRecordsͰϙʔϦϯά var kinesis = require('..'); ! # ετϦʔϜͱͭͳ͛Δ var

    stream = kinesis.stream('hoge'); ! # ϙʔϦϯάͯ͠औಘɽγϟʔυ͝ͱ΋ग़དྷ·͢ stream.getRecords(function(err, records){ console.log(new Date(), records[0].val.date); });
  11. 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Ϟδϡʔϧ
  12. 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(); }
  13. 4. ϙʔϦϯάʢ࠶ʣ co(function *(){ var gate = new Gate(); !

    stream.getRecords(gate.in()); ! var records = yield gate.out(); })();
  14. ࢥͬͨΑΓॻ͖ࠐΊΔɽͰ΋ ͪΐͬͱ஗͍? • max3000~ tps/shard put • ॻ͖ࠐΈ͗͢Δͱ݁ہऔΓग़͢·Ͱʹ͔͔࣌ؒΔɽ • ݁ہ400~700tpsఔ౓·Ͱ͍͚Δ͜ͱ͸֬ೝ

    • avg1sec get • ϙʔϦϯάࠐΈͰ͜ͷఔ౓ • 200msҎ಺ʹฦͬͯ͘ΔΘ͚͡Όͳ͍ • ॻ͖ࠐΜͰऔΓग़͢·Ͱʹͳ͔ͥϥά͕͋ͬͨΓͳ͔ͬͨΓ
  15. ײ૝ • ϑϧϚωʔδυʁ • KA͸ࣗ෼Ͱ؅ཧɽγϟʔυʹϫʔΧʔ৐ͤΒΕͳ͍ͷ͔ɽɽ ! • ϦΞϧλΠϜʁ • ϙʔϦϯά

    • औΓग़͢ͷʹϥά͕͚ͬ͜͏͋Δ ! • ύϑΥʔϚϯε • write͸ߴ͍ɽγϟʔυ૿΍ͤ͹͔ͳΓ͍͚ͦ͏