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

真剣.js / shinken-js

Sho Kusano
February 08, 2017

真剣.js / shinken-js

Sho Kusano

February 08, 2017
Tweet

More Decks by Sho Kusano

Other Decks in Technology

Transcript

  1. ੜెͷظ຤ࢼݧͭͬͯͯ͘Ϡό͍

    View Slide

  2. 쎙 쎅 썰 썫 썦
    썡썴썦썽
    썙 쎡 썟 쎁 썛 쎒 쎀
    ஗ 썛
    ͋ͷ೔ͷύονΛͳͨ͘͠੨೥ͷ૕ࣦͱ࠶ੜͷ෺ޠ

    View Slide

  3. 4MBDLͷνʔϜ਺͕രൃ͖ͯͨ͠
    !SPTZMJMMZ
    ݱࡏ͘Β͍ ೖͬͯͳ͍ͱ͜Ζ΋͋Δ

    View Slide



  4. 4 Q F F E
    δοαΠμΠδ

    View Slide

  5. (PךSFHFYQָ鹼ְ

    View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. $ go run regexp.go
    2.07745267s
    $ ruby regexp.rb
    1.709597
    $ node regexp.js
    0.129

    View Slide

  10. (P͕଎͍ͬͯݴͬͨͷ୭ͩΑ

    View Slide

  11. > In some areas Go kann keep up with Java but when it comes to string
    > operations ("regex-dna" benchmark), Go is even much slower than Ruby
    > or Python. Is the status quo going to improve anytime soon? And why is
    > Go so terribly slow when it comes to string/RegEx operations?
    You assume the benchmark is worth something.
    First of all, Ruby and Python are using C implementations
    of the regexp search, so Go is being beat by C, not by Ruby.
    Second, Go is using a different algorithm for regexp matching
    than the C implementations in those other languages.
    The algorithm Go uses guarantees to complete in time that is
    linear in the length of the input. The algorithm that Ruby/Python/etc
    are using can take time exponential in the length of the input,
    although on trivial cases it typically runs quite fast.
    In order to guarantee the linear time bound, Go's algorithm's
    best case speed a little slower than the optimistic Ruby/Python/etc
    algorithm. On the other hand, there are inputs for which Go will
    return quickly and Ruby/Python/etc need more time than is left
    before the heat death of the universe. It's a decent tradeoff.
    http://swtch.com/~rsc/regexp/regexp1.html
    Russ
    at Golang-nuts
    IUUQTHSPVQTHPPHMFDPNGPSVNNTHHPMBOHOVUTENBFGK2ZH/:R3UT.+

    View Slide

  12. ೖྗจࣈྻͷ௕͞ʹԠͯ͡ઢܗʹॲཧ͕࣌ؒ৳ͼΔ
    ˠϢʔβʔͷೖྗͱ͔͕Ϡόͯ͘΋ॲཧ͕࣌ؒอূ͞ΕΔ
    ˠ࠷దͳέʔε ϓϩάϥϚͷೖྗ
    ͳͲʹରͯ͠͸
    ɹ3VCZ΍1ZUIPOʹൺ΂ͯ஗͍

    View Slide

  13. SFHFYQ͸ආ͚Α͏
    ৽نʹQBDLBHFΛ࢖͏ͱ͖͸DMPOFͯ͠HJUHSFQSFHFYQ҆ఆ

    View Slide


  14. (PדTMJDFך⹛涸然⥂ָ鹼ְ

    View Slide

  15. View Slide

  16. View Slide

  17. ByAppend-4 20000 81987 ns/op 385784 B/op 20 allocs/op
    ByIndex-4 100000 16803 ns/op 81920 B/op 1 allocs/op

    View Slide

  18. ಈతʹTMJDFʹཁૉΛ௥Ճ͢Δͱ
    Ұఆͷ௕͞Λ௒͑Δͱ࠶֬อ͢Δ

    View Slide

  19. ཁૉ਺͕Θ͔͍ͬͯΔ৔߹ͳΒ
    ͦͷαΠζͷΩϟύγςΟΛ
    ࣄલʹ֬อ͓ͯ͘͠΂͖

    View Slide

  20. (Pד8SJUFS׾ֲתֻ⢪ֲ

    View Slide

  21. )551ϨεϙϯεͰ+40/ΛૹΔࡍʹॻ͖͕ͪͳίʔυ

    View Slide

  22. func Endpoint(
    rw http.ResponseWriter,
    req *http.Request,
    ) {
    bytes, err := json.Marshal(model)
    rw.Write(bytes)
    }
    Ұ౓CZUFTMJDFΛੜ੒ͯ͠͠·͍ͬͯΔ

    View Slide

  23. func Endpoint(
    rw http.ResponseWriter,
    req *http.Request,
    ) {
    encoder := json.NewEncoder(rw)
    encoder.Encode(model)
    }
    CZUFTMJDF͕࡞ΒΕͳ͍

    View Slide

  24. Bytes-4 200 7007896 ns/op 3915804 B/op 19 allocs/op
    Writer-4 200 6565790 ns/op 1074462 B/op 5 allocs/op

    View Slide

  25. 8SJUFSΛแΉ8SJUFSͳͲ΋࡞ΕΔ #BTFH[JQ

    ͷͰɺ׆༻͢ΔͱΑΓศརͰΘ͔Γ΍͘͢࢖͍͜ͳͤΔ

    View Slide

  26. BMMPDճ਺͕ݮΕ͹୯७ʹߴ଎Խʹ΋د༩͢ΔͷͰ
    ੵۃతʹ׆༻͠·͠ΐ͏ ͲͪΒ͔ͱ͍͑͹ϝϞϦෛՙܰݮ

    View Slide

  27. ࡉ͔͍
    ੵΈॏͶ
    ࡉ͔͍
    ੵΈॏͶ
    ࡉ͔͍
    ੵΈॏͶ
    ࡉ͔͍
    ੵΈॏͶ

    View Slide

  28. ଎͘ͳΔ
    ˣ
    μΠϨΫτͳتͼ

    View Slide

  29. ΍͍͖ͬͯ·͠ΐ͏

    View Slide


  30. View Slide

  31. ෇࿥

    View Slide

  32. ͜ ͷ Ұ ೥ Ͱ ͷ
    ۜߦͷಈ͖

    View Slide


  33. ๺෦৴૊ۜߦഇۀ

    View Slide


  34. େ֞৴ۚͱ੢ೱ৴͕ۚ
    ߹ซ͠େ֞੢ೱ৴ۚʹ

    View Slide


  35. ෢෦৴ۚɺ๛ӫ೶ڠഇۀ
    ࠇ෦೶ڠͱࠇ෦ࢢ৴༻೶ڠ
    ͕߹ซ͠ɺࠇ෦ࢢ೶ڠʹ

    View Slide

  36. ͳΜ͔௕͘ͳ͖ͬͯͨΜͰলུ͢Δͱ

    View Slide

  37. ৴ۚͷഇۀͱ૑ۀ
    ͙͢Θ͔Δ೥ͷۜߦτϨϯυ
    ೶ڠͷ߹ซϥογϡ
    ΞδΞݍࠃ֎ۜߦͷਐग़

    View Slide

  38. ৴ۚͷഇۀͱ૑ۀ
    ݹ͔͘Β͋Δ৴ۚͷղࢄͱ
    ৽ڵͷ৴૊ ࿑૊
    ۜߦ͕
    ೖΕସΘΔΑ͏ʹಈ͍͍ͯΔ
    ྫࢁܗݝҩࢣ৴૊ɺࡾॏݝ৬һ৴૊

    View Slide

  39. ೶ڠͷ߹ซϥογϡ
    ͍Θ͖ࢢ೶ۀڠಉ૊߹ɺ
    ܊ࢁࢢ೶ۀڠಉ૊߹ɺͨΉΒ೶ۀڠಉ૊߹ɺ
    ͍Θ͖த෦೶ۀڠಉ૊߹ɺ;ͨ͹೶ۀڠಉ૊߹
    ෱ౡ͘͞Β೶ۀڠಉ૊߹
    ˣ
    ஍۠୯Ґͩͬͨ೶ڠ͕ɺݝ୯ҐʹҠߦͭͭ͋͠Δ

    View Slide

  40. ೥ʹਐग़͖ͯͨ͠ࠃ֎ۜߦ
    ϑΟϦϐϯɾφγϣφϧɾόϯΫ
    ୆৽ᅳࡍ঎ۀ
    φγϣφϧΦʔετϥϦΞ
    ΞδΞݍࠃ֎ۜߦͷਐग़

    View Slide

  41. ۜߦ৘ใΛ௥͏ͱ
    ࢿۚݯྲྀಈͬΆ͍΋ͷ͕ݟ͑ͯ
    ͘͢͝ݏͳؾ࣋ͪʹͳָ͍ͬͯ͠

    View Slide

  42. ࠷ۜ
    ߴߦ

    View Slide


  43. View Slide