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

あなたってどんな方(型)?/ kamakura.go#4

あなたってどんな方(型)?/ kamakura.go#4

kamakura.go#4の発表資料

Konboi

May 25, 2018
Tweet

More Decks by Konboi

Other Decks in Technology

Transcript

  1. ͋ͳͨͬͯͲΜͳํ(ܕ)ʁ
    2018/05/25 kamakura.go#4

    View full-size slide

  2. ࣗݾ঺հ
    • ໼ਧྒྷհ a.k.a ˏKonboi
    • ໘ന๏ਓΧϠοΫ
    • SGࣄۀ෦
    • αʔόʔαΠυΤϯδχΞ/

    ΤϯδχΞϦϯάϚωʔδϟʔ
    • Go/Perl/AWS

    View full-size slide

  3. ࠓ೔ͷ͓࿩

    View full-size slide

  4. ͋ͳͨͬͯͲΜͳํ(ܕ)ʁ

    View full-size slide

  5. GoͷϓϩδΣΫτͰδϣϒΩϡʔΛ

    Amazon SQSΛ࢖࣮ͬͯݱͨ͠࿩

    View full-size slide

  6. GoͷϓϩδΣΫτͰδϣϒΩϡʔΛ

    Amazon SQSΛ࢖࣮ͬͯݱͨ͠࿩

    View full-size slide

  7. δϣϒΩϡʔ
    • a.k.a ϝοηʔδΩϡʔ/λεΫΩϡʔ
    • Perl
    • Gearman
    • Q4M
    • Rails
    • ActiveJob
    • Sidekiq
    • Shoryuken

    View full-size slide

  8. δϣϒΩϡʔ
    • ඇಉظʹॲཧΛߦ͍͍ͨ
    • ϩδοΫͷॲཧΛ෼͚͍ͨ
    • ex)
    • Ϣʔβʔొ࿥ޙϝʔϧΛૹΔ
    • ΫΤετΫϦΞ࣌ͷΫΤετΫϦΞνϟϨϯδͷୡ੒
    • ϑϨϯυΛΫΤετʹ࿈Εͯߦͬͨ࣌ʹ

    ϑϨϯυ΁ϙΠϯτ෇༩

    View full-size slide

  9. GoͷϓϩδΣΫτͰδϣϒΩϡʔΛ

    Amazon SQSΛ࢖࣮ͬͯݱͨ͠࿩

    View full-size slide

  10. Amazon SQS
    • Simple Queue Service ͷུ
    • ϚωʔδυͷΩϡʔΠϯάαʔϏε
    • ඪ४ΩϡʔͱFIFO(First In First Out)Ωϡʔͷ2ͭ
    • ͨͩ͠ɺFIFO͸౦ژϦʔδϣϯະରԠ

    View full-size slide

  11. Amazon SQS
    • String,Number,BinaryͷσʔλΛ

    ϝοηʔδຊจʹ֨ೲՄೳ
    • Attributeͱݺ͹ΕΔϑΟʔϧυʹ

    ຊจͱ͸ผʹ৘ใ͕֨ೲՄೳ
    • Ұఆ࣌ؒܦͭͱ

    ࠶౓ϝοηʔδ͕औಘͰ͖Δ
    • ϝοηʔδ͸ࣗ਎Ͱ࡟আ͢Δඞཁ͕༗Δ

    View full-size slide

  12. ͦ΋ͦ΋ͳΜͰ

    Amazon SQSΛ࢖͏ͷ͔ʁ

    View full-size slide

  13. Amazon SQSΛ࢖͏ཧ༝
    • ϑϧϚωʔδυ
    • ؅ཧίετμ΢ϯ
    • ଞͷϓϩδΣΫτͰ࠾༻ࡁΈ
    • ͨͩ͠
    • SQSಠࣗͷΫηΛߟྀ͢Δඞཁ͕͋Δ
    • ࠓճ͸͜ͷ෦෼͸࿩͞ͳ͍ͷͰڵຯ͋Δਓ͸

    ࠙਌ձͰ

    View full-size slide

  14. GoͷϓϩδΣΫτͰδϣϒΩϡʔΛ

    Amazon SQSΛ࢖࣮ͬͯݱͨ͠࿩

    View full-size slide

  15. GoͷϓϩδΣΫτ
    • ొ৔ਓ෺
    • Job
    • ඇಉظʹ࣮ߦ͍ͨ͠ॲཧ
    • Queue
    • JobΛग़͠ೖΕ͢Δ౔؅ͷΠϝʔδ
    • JobQueue
    • JobΛQueue͔ΒऔΓग़࣮ͯ͠ߦ͢Δ

    View full-size slide

  16. GoͷϓϩδΣΫτ
    • ίʔυͩͱ͜Μͳײ͡

    View full-size slide

  17. GoͷϓϩδΣΫτ
    +PC2VFVF
    2VFVF
    +PC

    View full-size slide

  18. GoͷϓϩδΣΫτ
    +PC2VFVF
    2VFVF
    +PC

    View full-size slide

  19. GoͷϓϩδΣΫτ
    +PC2VFVF
    2VFVF
    +PC

    View full-size slide

  20. GoͷϓϩδΣΫτ
    +PC2VFVF
    2VFVF
    +PC
    3VO

    View full-size slide

  21. ͨͱ͑͹Queue͕

    channelͷ৔߹

    View full-size slide

  22. Queue͕channelͷ৔߹
    • channelΛ༻͍ͨQueueͷίʔυ

    View full-size slide

  23. Queue͕channelͷ৔߹
    • ਤ +PC2VFVF
    2VFVF
    +PC
    DIBOOFM

    View full-size slide

  24. Queue͕channelͷ৔߹
    • ਤ +PC2VFVF
    2VFVF
    +PC
    DIBOOFM

    View full-size slide

  25. Queue͕channelͷ৔߹
    • ਤ +PC2VFVF
    2VFVF
    +PC
    DIBOOFM

    View full-size slide

  26. Queue͕channelͷ৔߹
    • ਤ +PC2VFVF
    2VFVF
    DIBOOFM
    +PC
    3VO

    View full-size slide

  27. ͨͱ͑͹Queue͕

    Amazon SQSͷ৔߹

    View full-size slide

  28. ͨͱ͑͹Queue͕Amazon SQSͷ৔߹
    • amazon sqsΛ༻͍ͨQueueͷίʔυ

    View full-size slide

  29. • ਤ
    ͨͱ͑͹Queue͕Amazon SQSͷ৔߹
    2VFVF
    +PC

    View full-size slide

  30. • ਤ
    ͨͱ͑͹Queue͕Amazon SQSͷ৔߹
    +PC
    2VFVF

    View full-size slide

  31. • ਤ
    ͨͱ͑͹Queue͕Amazon SQSͷ৔߹
    424.FTTBHFͷ#PEZʹ

    +PCͷ৘ใΛ+40/ʹͯ͠ૹΔ
    2VFVF

    View full-size slide

  32. • ਤ
    ͨͱ͑͹Queue͕Amazon SQSͷ৔߹
    424.FTTBHFͷ#PEZͷ

    +40/Λ+PCʹ6ONBSTIBM
    2VFVF

    View full-size slide

  33. • ਤ
    ͨͱ͑͹Queue͕Amazon SQSͷ৔߹
    +PC
    2VFVF

    View full-size slide

  34. • ਤ
    ͨͱ͑͹Queue͕Amazon SQSͷ৔߹
    +PC
    3VO
    2VFVF

    View full-size slide

  35. ͪΐͬͱ଴ͯΑ…✋

    View full-size slide

  36. ຊ୊

    (΍ͬͱ)


    ~͋ͳͨͬͯͲΜͳํ(ܕ)ʁ~
    ࢒Γ෼͙Β͍ཉ͍͠

    View full-size slide

  37. લஔ͖͕௕͍ͯ͘͢·ͤΜ

    View full-size slide

  38. ຊ୊

    (΍ͬͱ)


    ~͋ͳͨͬͯͲΜͳํ(ܕ)ʁ~
    ࢒Γ෼͙Β͍ཉ͍͠
    Amazon SQSͷϝοηʔδ͔ΒJobʹม׵͢Δ

    View full-size slide

  39. Amazon SQSͷϝοηʔδ͔ΒJobʹม׵͢Δ
    • Job͕1छྨͩͬͨΒ໰୊ͳ͍
    • ͔࣮͠͠ࡍ͸
    • ΫΤετΫϦΞϛογϣϯͷδϣϒ
    • QuestClearJob
    • ϑϨϯυʹϙΠϯτΛ෇༩͢Δδϣϒ
    • SendFriendPointJob
    • Unmarshalઌͷܕ͕ҟͳΔ

    View full-size slide

  40. SQS͔ΒऔΓग़ͨ͠ϝοηʔδΛ

    ద੾ʹUnmarshal͢Δඞཁ͕͋Δ

    View full-size slide

  41. औΓग़ͨ͠λΠϛϯάͰ

    ͋ͳͨ͸ͲΜͳํ(ܕ)͔஌͍ͬͯͯ

    structΛ࡞Δඞཁ͕͋Δ

    View full-size slide

  42. Ͳ͏΍ͬͯղܾ͔ͨ͠

    View full-size slide

  43. reflect
    • reflect.New(reflect.Type)
    • reflect.Value͕ฦͬͯ͘Δ
    • reflect.Value.Interface()
    • Interface{}͕ฦͬͯ͘Δ
    • ͜ΕͰstructΛੜ੒(?)͢Δࣄ͕Ͱ͖Δ

    View full-size slide

  44. ͜ΕΛઌఔͷSQS Queueʹ

    ൓ө͢Δͱ

    View full-size slide

  45. SQS Queueʹ൓ө͢Δ

    View full-size slide

  46. SQS Queueʹ൓ө͢Δ

    View full-size slide

  47. SQS Queueʹ൓ө͢Δ

    View full-size slide

  48. ิ଍
    • ͳΜͰJobຖʹQueueΛ༻ҙ͠ͳ͔ͬͨͷʁ
    • طʹJobͷ਺͕10਺ݸ͋Γ

    ࠓޙ΋૿͑Δ༧ఆ
    • ৽نͰJobΛ࡞Δ౓ʹ։ൃ؀ڥ/ຊ൪ͱ
    QueueΛ࡞Δͷ͸ΦϖϨʔγϣϯ͕൥ࡶ

    View full-size slide

  49. ิ଍
    • Queueଆ͕ԿͷJob͕ग़ೖΓ͢Δ

    ͔͸஌Δඞཁ͕ͳ͘ɺ

    ґଘ͠ͳ͍ํ͕Α͍ͱ͍͏݁࿦ʹ

    View full-size slide

  50. ·ͱΊ
    • GoͷϓϩδΣΫτͰδϣϒΩϡʔΛ

    Amazon SQSΛ࢖࣮ͬͯݱͨ͠࿩
    • reflect.New/reflect.Value/r.V.Interface() 

    ͔ΒಈతʹܕΛੜ੒ͯ͠ղܾ

    View full-size slide

  51. Ҏ্

    ͋ͳͨͬͯͲΜͳํ?(ܕ)

    View full-size slide

  52. ࢀߟURL
    • https://aws.amazon.com/jp/sqs/
    • http://awsdocs.s3.amazonaws.com/SQS/
    latest/sqs-gsg.pdf
    • https://golang.org/pkg/reflect/
    • ΈΜͳͷGoݴޠ

    View full-size slide