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

Golang @ISUCON

Golang @ISUCON

GoCon 2014 Autmun

05e8adce66be4e80390a29ace0075161?s=128

y_matsuwitter

November 30, 2014
Tweet

Transcript

  1. Golang @ISUCON y_matsuwitter

  2. !Z@NBUTVXJUUFS Gunosy inc., ࣥߦ໾һ ! Goྺ1೥ऑ͘Β͍ ! όϥϯεϘʔϧਖ਼࠲ͷਓ

  3. ීஈͷۀ຿ GoʹΑΔAPIαʔόߏங (2014.3~) iOS/AndroidͷΞϓϦ։ൃ Django/RailsʹΑΔWebApp։ൃ

  4. ʊਓਓਓਓਓਓਓਓਓਓਓਓਓʊ ʼɹGolangΤϯδχΞืूதɹʻ ʉY^Y^Y^Y^Y^Y^Y^Y^Y^Yʉ

  5. ࠓ೔ͷ࿩ ॳΊͯͷISUCONΛGolangͰઓͬͯΈͨ࿩ ※GolangҎ֎ͷ࿩͸͠·ͤΜ Ґͱத్൒୺ͳ݁ՌͰ͕ͨ͠ʜ

  6. ISUCONͱ͸ Iikanjini Speed Up CONtest ! 8࣌ؒͰ༩͑ΒΕͨWebAppΛग़དྷΔݶΓߴ ଎Խ͢Δίϯςετ

  7. ༧બ αʔό: 1୆ େ఍͸MySQLΛDB ࠓ೥͸ۜߦͷϩάΠϯϖʔδ͕୊ࡐͰͨ͠

  8. ܾউ αʔό: 3~4୆ ը૾ॲཧ΍ಈըͷ഑৴ͳͲ͋Δఔ౓ෛՙͷߴ ͍ॲཧΛؚΉWebApp ࠓ೥͸ಈը޿ࠂͷ഑৴αʔόͰͨ͠

  9. ߴ଎ͳWebαʔόͷͨΊʹ ϦιʔεΛ࢖͍੾Δ CPU … Encode/decode, ը૾ॲཧͳͲ Memory … ϓϩηε্ͷσʔλྔ Data

    Transfer … αʔόؒɺαʔόΫϥΠΞϯτؒͷ૯௨৴ྔ ! ͦͷ্Ͱద੾ͳॲཧʹϦιʔεΛׂΓ౰ͯΔ
  10. ݴޠੑೳ͸ ܾఆతͳࠩʹ͸ͳΒͳ͍

  11. Why Go? վળͷޮ཰ͷߴ͞ - ߏจ͕SimpleͳͨΊ୹࣌ؒͷνʔϜ։ൃ޲͖ - ฒྻɾฒߦॲཧͰͷϝϞϦपΓͷѻָ͍͕ - σϓϩΠָ͕ -

    ඪ४ύοέʔδ͕ඇৗʹ࣮༻త
  12. औΓ૊Μͩ͜ͱ 1. ϓϩηεΩϟογϡ 2. λεΫ෼ࢄॲཧ

  13. ϓϩηεΩϟογϡ σʔλΛϓϩηε্ʹશͯอ͓࣋ͯ͘͠ ! ӬଓԽ͸ద౓ͳλΠϛϯάͰRedisʹอଘͳ ΓϑΝΠϧʹdumpͳΓ͢Δ

  14. ੔߹ੑ ౰વɺෳ਺ͷGoroutine͔ΒಡΈॻ͖͞ΕΔ ͨΊ஋ͷ੔߹ੑΛอূ͢Δඞཁ͕͋Δ

  15. Race Condition ڝ߹͢Δม਺ૢ࡞Λߦ͏ͱෆ҆ఆͳڍಈ Goroutine·͍ͨͰڞ༗ͷ஋ΛಡΈॻ͖͢Δ ࡍ͸race conditionΛආ͚ΔͨΊLock͕ඞཁ

  16. sync ֤छͷϩοΫΛѻ͏ύοέʔδ ! sync.RWMutex - ReadΛWriteͰϩοΫϨϕϧΛ෼཭ͨ͠Lock sync/atomic - Χ΢ϯλͳͲͷॲཧΛ࡞Δͷʹॏๅ

  17. atomic.Value from golang1.4 ! ϓϩηε্ʹatomicʹσʔλߋ৽Ͱ͖Δετ Ξͱͯ͠ઃܭ͞Ε͍ͯ·͢

  18. None
  19. ಡΈࠐΈଆ͸7BMVF͔Β-PBE

  20. ॻ͖ࠐΈଆ͸-PDLऔͬͨ͋ͱ 7BMVFʹ4UPSF

  21. λεΫͷ෼ࢄॲཧ ཁ݅ - ॲཧʹ͔͔࣌ؒΔ΋ͷΛඇಉظɺ͔ͭฒߦ࣮ߦ ਺Λ੍ݶ࣮ͯ͠ߦ͍ͨ͠ ! - ը૾ɾಈըͳͲ͸ॏෳͯ͠ॲཧͨ͘͠ͳ͍

  22. Task Queueing capacity෇͖ͷchannelΛ࢖͏ goroutine͕ͦͷ··workerతʹ࢖͑Δ

  23. None
  24. ॏෳॲཧΛආ͚Δ ྫ͑͹ը૾ॲཧதʹɺͦͷը૾Λऔಘ͠ʹདྷ ΔϦΫΤετΛfailͤͯ͞͸ͳΒͳ͍ ! ͔͠͠ɺऔಘ࣌ʹॏෳॲཧ͸͕࣌ؒ໪ମແ͍

  25. αʔό͕1୆ͷ৔߹

  26. sync.Cond ॲཧதͷ΋ͷΛબ୒తʹ଴ͭ

  27. None
  28. αʔό͕ෳ਺୆ͷ࣌

  29. y-matsuwitter/mcond ෳ਺୆ͷαʔόؒͰsync.CondΛѻ͑ΔΑ͏ ʹͨ͠΋ͷ ! Redis + net/httpΛར༻

  30. ೋ୆ͷαʔόͰͷmcond

  31. ॲཧଆ ಡΈࠐΈଆ

  32. ॲཧઌΛৼΓ෼͚Δ

  33. stathat/consistent ίϯγεςϯτϋογϡϥΠϒϥϦ ! Ұఆͷ໊લʹରͯ͠ඞͣಉ͡ॲཧઌΛܾఆ ࠓճ͸ଳҬΛ࢖͍௵ͨ͢Ίෳ਺ͷwebdav αʔόʹৼΓ෼͚Δ༻్Ͱར༻

  34. None
  35. ͪͳΈʹ ഊҼ͸Cache-Control HeaderͰͨ͠ IUUQTTV[VSJKQZ@NBUTVXJUUFSUTIJSUNCMBDL

  36. ࠷ޙʹ

  37. ProductionͰ΋࢖͓͏

  38. None
  39. ࢀߟ ඪ४ύοέʔδ http://golang.org/pkg/ go1.4 http://tip.golang.org/doc/go1.4 mcond https://github.com/y-matsuwitter/mcond consistent https://github.com/stathat/consistent