Asynchronous Networking Patterns - mercari.go #3

60e652d0244f47d2da4e1f7e712f9328?s=47 K
September 21, 2018

Asynchronous Networking Patterns - mercari.go #3

Asynchronous Networking Patterns の話を聞いたので理解しようと頑張ってまとめました。

- オリジナルスライド: https://speakerdeck.com/filosottile/asynchronous-networking-at-gophercon-2018
- YouTube: https://www.youtube.com/watch?v=afSiVelXDTQ
- オリジナルコード: https://github.com/FiloSottile/mostly-harmless/tree/master/talks/asyncnet
- mercari.go #3 の発表に使ったコード: https://github.com/Code-Hex/network

60e652d0244f47d2da4e1f7e712f9328?s=128

K

September 21, 2018
Tweet

Transcript

  1. "TZODISPOPVT /FUXPSLJOH1BUUFSOT NFSDBSJHP

  2. !DPEFIFY !$PEF)FY w .JDSPTFSWJDFT%FWFMPQNFOU w 1FSM(P

  3. "TZODISPOPVT /FUXPSLJOH1BUUFSOT

  4. !DPEFIFY !$PEF)FY w 'JMJQQP7BMTPSEB w $SZQUPHPQIFS w (PUFBN w (PPHMF

    !'JMP4PUUJMF !'JMP4PUUJMF
  5. w εϥΠυ w IUUQTTQFBLFSEFDLDPNpMPTPUUJMFBTZODISPOPVT OFUXPSLJOHBUHPQIFSDPO w εϐʔΧʔಈը w IUUQTXXXZPVUVCFDPNXBUDI WBG4J7FM9%52

    w ղઆϒϩά w IUUQTBCPVUTPVSDFHSBQIDPNHP HPQIFSDPOBTZODISPOPVTOFUXPSLJOH QBUUFSOT w جຊతʹ-JWFDPEJOHͰͨ͠
  6. ͜ͷτʔΫʹ͍ͭͯ w "DDFQUJOHDPOOFDUJPOT w "TJNQMFQSPYZ w 1BSTJOH5-4 w 4FSWF5-4

  7. ඇಉظͷίωΫγϣϯύλʔϯ

  8. ඇಉظωοτϫʔΩϯά w ϦΫΤετ͝ͱʹεϨουΛ্ཱͪ͛Δ w γϯϓϧͳϩδοΫ w ϦΫΤετ͕͋ΔͨͼʹεϨουΛ্ཱͪ͛Δ ͷͰ͔ͳΓͷϦιʔεΛඅ΍͢ w *NH3FGIUUQTCJUMZ%K/IL

  9. ඇಉظωοτϫʔΩϯά w Πϕϯτϧʔϓ OHJOY΋͜ͷํࣜ  w ΠϕϯτΛΠϕϯτΩϡʔʹಥͬࠐΜͰ͍͘ w ֤ϫʔΧʔ͕Ωϡʔ͔ΒΠϕϯτΛͱͬͯ࢓ࣄΛ ࢓ࣄ͍ͯ͘͠

    w ϒϩοΫͨ͠ΒผͷΠϕϯτΛऔΓग़ͯ͠࢓ࣄΛ ͢Δ w ߟ͑Δ͜ͱ͕ͨ͘͞Μ͋Δ w *NHIUUQTCJUMZ0#HUTQ
  10. ඇಉظωοτϫʔΩϯά w (PͰ͸(PSPVUJOFͰϦΫΤετ͝ͱʹ
 ͭͷ(PSPVUJOFΛ࡞੒͢Δ w (PSPVUJOF͸ੜ੒ίετ͕௿͍ w (Pͷεέδϡʔϥʔ͕ॲཧશମతʹϒϩοΫ͠ͳ ͍Α͏ʹ্ख͘εέδϡʔϧͯ͘͠ΕΔ w

    ͋Δ(PSPVUJOF͕ϒϩοΫ͍ͯ͠Δؒɺଞͷ (PSPVUJOFͷॲཧΛߦ͏ w *NHIUUQTCJUMZ.1"&
  11. "DDFQUJOHDPOOFDUJPOT 5$1ΛBDDFQU͢ΔίωΫγϣϯαʔόʔͷ࣮૷

  12. OFUQBDLBHF

  13. OFUQBDLBHF w OFU$POO w ωοτϫʔΫίωΫγϣϯͷͨΊͷJOUFSGBDF w ΫϥΠΞϯτ͸ίωΫγϣϯͰ࿈ଓͯ͠σʔ λΛసૹͰ͖Δ w OFU-JTUFOFS

    w ωοτϫʔΫϦεφʔͷͨΊͷJOUFSGBDF w "DDFQUϝιουఏڙͯͯ͠ίωΫγϣϯΛडཧ ͢Δ͜ͱ͕Ͱ͖Δ
  14. Α͘ݟΔίωΫγϣϯͷྫ

  15. w (PSPVUJOFͰαʔϒ͢Δ͜ͱʹΑΓෳ਺ͷΫϥΠ Ξϯτͱͷ΍ΓऔΓΛߦ͏͜ͱ͕Ͱ͖Δ w αʔϒ಺ͰؾΛ͚ͭΔ͜ͱ w ॲཧͷ࠷ޙͰίωΫγϣϯͷDMPTFΛߦ͏Α͏ ʹ͢Δ w 5JNFPVUΛඞͣઃఆ͢Δ

    w ίωΫγϣϯͷுΓͬͺͳ͠Λ๷͙ TFSWF෦෼ͰͰ͖Δ͜ͱ
  16. "TJNQMFQSPYZ 4JNQMFͳQSPYZͷ࣮૷

  17. QSPYZͱ͸ 
 IUUQTCJUMZY'WL-

  18. w /HJOYͱಉ͘͡Β͍ૣ͍Β͍͠ w TQMJDF  ͱ͍͏γεςϜίʔϧΛ࢖ͬͯΔ w ΧʔωϧɺϢʔβʔۭؒͷؒͰੜ͡Δσʔλͷ ΍ΓऔΓʹίϐʔΛߦΘͳ͍ w

    NBOIUUQTCJUMZ/SU)W' w 5$1$POO3FBE'SPNͷதͰ࣮૷͞ΕͯΔ QSPYZͷྫ
  19. 1BSTJOH5-4 UMTͷQBSTFΛߦ͏

  20. w 5-4͸FOEUPFOEͰίωΫγϣϯͷ҉߸ԽΛఏ ڙ͢Δ w 4FSWFS/BNF*OEJDBUJPO 4/* ͰͲΜͳΫϥΠ Ξϯτ͕઀ଓ͖ͯͯ͠Δ͔஌Δ͜ͱ͕Ͱ͖Δ w ࠓճ͸4/*ͷύʔεͷΈΛߦ͍ͬͯ·ͨ͠

    w *NHIUUQTCJUMZ16UJZQ 1BSTJOH5-4
  21. 1BSTJOH5-4 w 4/*Λ஌ΔͨΊʹ5-41MBJOUFYU Λύʔε͢Δ w $POUFOU5ZQF͸
 CJUCZUFͰදݱ w 1SPUPDPM7FSTJPOCZUF w

    MFOHUICZUF w .TH5ZQF͸$MJFOU)FMMP
  22. 1BSTJOH5-4

  23. 1BSTJOH5-4 1BSTJOH5-4

  24. ίϯςϯπ΋औಘ͍ͨ͠

  25. w $POO͔Β$MJFOU)FMMPͷ෦෼͸औಘͨ͠ w #V⒎FSͱDPOOΛ࢖ͬͯશ෦SFNPUFʹૹΔ w DPOOͷ࠶ར༻ w JP.VMUJ3FBEFSΛ࢖͏ w *NHIUUQTCJUMZ16UJZQ

    1BSTJOH5-4
  26. 1BSTJOH5-4

  27. 1BSTJOH5-4

  28. 1BSTJOH5-4

  29. 4FSWF5-4 QSPYZଆͰ5-4ͷTFSWFΛߦ͏

  30. UMT$POO͸
 OFU$POOͷϥούʔ

  31. 4FSWF5-4

  32. $ mkcert localhost (brew install mkcert && mkcert -install)

  33. ͜ͷτʔΫͷ·ͱΊ w OFUQBDLBHFΛ࢖ͬͯQSPYZΛ࡞੒ͨ͠ w /HJOYͷΑ͏ͳෳࡶʹΠϕϯτϧʔϓΛ؅ཧͤͣɺ ಉ͡Α͏ͳύϑΥʔϚϯεΛग़ͤΔQSPYZΛ໿ ߦͰॻ͘͜ͱ͕Ͱ͖ͨ w 3FGIUUQTCJUMZQQ(6