Slide 1

Slide 1 text

ϢχΫϩͷ Ϩδ͔ΒֶͿ (PSPVUJOF ZBQDPKJZBQDPKJ" YAP(achimon)C::Asia Hachioji 2016 mid in Shinagawa @catatsuy

Slide 2

Slide 2 text

ΞδΣϯμ • ࣗݾ঺հ • ϢχΫϩͷϨδʹ͍ͭͯ • GoݴޠͰ࣮૷ͨ͠ϢχΫϩͷϨδͱͦͷख๏ • ·ͱΊ

Slide 3

Slide 3 text

ࣗݾ঺հ w ֤छ4/4Λ!DBUBUTVZͰ΍͍ͬͯΔ w ͔͍ͨͭͱݺ͹ΕΔ͜ͱ͕ଟ͍ w ϐΫγϒגࣜձࣾͰΠϯϑϥˠQJYJWϝϯςφϯεɾ޿ࠂ݉೚ʹ w ୯ஶʰQJYJWΤϯδχΞ͕ڭ͑Δϓϩάϥϛϯάೖ໳ʢ੕ւࣾ৽ ॻʣʱ w ϐΫγϒࣾ಺ͷඇΤϯδχΞ޲͚ͷϓϩάϥϛϯάݚमͷॻ੶Խ w *46$0/ग़୊νʔϜͷਓ w ΈΜͳग़ͯͶ

Slide 4

Slide 4 text

ࠓճͷ࿩ w ϢχΫϩʢ৽॓ͷϏοΫϩʣͷϨδ͸٬ʢλεΫʣΛޮ཰ྑ͘ ࡹ͘࢓૊Έ͕͋Δ w ϢχΫϩͷϨδΛ(PݴޠͰදݱ͠ɺͦ͜Ͱ࢖ΘΕͨख๏ͷ঺հ w ಛʹHPSPVUJOFͱνϟωϧ w Ұ෦؆ུԽ͍ͯ͠·͕͢ɺ࣮༻ՄೳͳίʔυͰ͢ w (PݴޠͷHPSPVUJOFͱνϟωϧ͸γϯϓϧͳϧʔϧ͔͠ͳ͍ ͕ɺͱͯ΋ύϫϑϧ w ޮ཰ྑ͘$16ͷίΞΛ࢖͍੾ΕΔίʔυΛॻ͚Δ

Slide 5

Slide 5 text

ϢχΫϩͷϨδͷߦྻ ٬ ෰ΛͨͨΉਓ Ϩδͷਓ ٬͕ҰྻʹϨδʹฒͿ Ϩδ͕ۭ͍ͨΒ ٬͸ۭ͍ͨϨδʹߦ͘

Slide 6

Slide 6 text

Ϩδͷਓʹ٬͕෰Λ౉ͯ͠ Ϩδͷਓ͕஋ஈΛܭࢉ͢Δ ෰T ٬ Ϩδͷਓ

Slide 7

Slide 7 text

͓ۚΛ෷ͬͯ঎඼Λड͚औΔ ᶄྉۚΛ੥ٻ ᶅ͓ۚΛࢧ෷͏ ᶃ෰Λ౉͢ ᶆͨͨΜͩ෰Λ౉͢ Ϩδͷਓ ಉظΛऔΔ ٬ ෰ΛͨͨΉਓ ᶅͱᶆͷ྆ํ͕ऴྃͯ͠ॲཧ͕ऴྃ

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

(Pͷߏ଄ମ w (Pͷߏ଄ମ͸pFMEΛ࣋ͪɺܕͱ໊લΛࢦఆ͢Δ w sync.Mutex͸TZODύοέʔδͰఆٛ͞Ε͍ͯΔߏ଄ମ w ແ໊ͰຒΊࠐΉͱDPNNFSߏ଄ମʹsync.Mutexͷ ϝιου͕ຒΊࠐ·Εͯ࢖͑ΔΑ͏ʹͳΔ w sync.Mutex͸ޙͰઆ໌͢Δ w []*clothes͸DMPUIFTͷϙΠϯλͷTMJDF w ࣅͨ֓೦Ͱ഑ྻͱTMJDF྆ํ࢖͑Δ͕ɺ഑ྻΑΓ΋TMJDF Λ࢖͏ʢͱ͍͏ΑΓ഑ྻ͸΄΅࢖Θͳ͍ʣ w (Pͷ഑ྻ͸ཁૉ਺ΛؚΊͯܕͳͷͰɺ్தͰαΠζ ΛมߋͰ͖ͳ͍ w TMJDFͷཁૉ਺͸ม͑ΒΕΔ w ϝιου΋ఆٛͰ͖Δʢ$ݴޠͷߏ଄ମͱ͸ҧ͏ʣ

Slide 10

Slide 10 text

٬Λฒ΂Δʢνϟωϧʣ w ૊ΈࠐΈͷNBLFؔ਺Λ࢖͏ͱνϟωϧͷॳظԽ͕Ͱ͖Δ w ୈҾ਺Ͱνϟωϧͷ༰ྔΛࢦఆ͢Δ w go func()ͷதͷॲཧ͸HPSPVUJOFͰ࣮ߦ͞ΕΔ w for {}͸ແݶϧʔϓ͕ͩɺHPSPVUJOFͷதͰ࣮ߦ͢Ε͹NBJOؔ਺ͷअຐΛͤͣ ʹॲཧΛͣͬͱ࣮ߦͰ͖Δ w νϟωϧ΁஋Λૹ৴͢Δͷ΋ड৴͢Δͷ΋Ͱߦ͏ w νϟωϧͷ௕͕͞ʹͳΔ·Ͱ٬Λૹ৴͢Δ w νϟωϧͷ௕͕͞ҎԼʹͳͬͨΒʹͳΔ·Ͱ٬Λૹ৴͢Δ w ຊ౰͸٬ʹΑͬͯങ͏΋ͷ͸ҧ͏͕ɺࠓճ͸શһಉ͡ʹͨ͠

Slide 11

Slide 11 text

ฒྻॲཧ਺Λ੍ޚ͢Δ w νϟωϧ͸༰ྔҎ্ͷ஋ΛૹΔͱ଴ͪʹͳΔ w ༰ྔͷνϟωϧͰฒྻ਺Λ੍ޚ͢Δ w ˠϨδʹਓ͍Δ w λεΫΛେྔʹಉ࣮࣌ߦ͢Δͱ๫૸͢ΔͷͰɺ࣮ ϓϩάϥϜͰ΋ඞཁ w ࣮ߦ͕ऴྃͨ͠Βνϟωϧܦ༝Ͱ௨஌͞Εͯɺ଴ ͪʹͳ͍ͬͯΔHPSPVUJOFͷॲཧ͕࢝·Δ w ˠϨδ͕ۭ͍ͨΒۭ͍ͨϨδʹ٬͕ߦ͘ • νϟωϧͷܕ͸int΍boolͰ΋ಈ͘ • ۭͷߏ଄ମstruct{}Λ࢖͏ͱνϟωϧͷ஋ʹ৘ ใΛ࣋ͨ͢͜ͱ͕Ͱ͖ͳ͍ͷͰɺਪ঑͞ΕΔ • cf: GoݴޠͰCPU਺ʹԠͯ͡ฒྻॲཧ਺Λ੍ݶ͢Δ | SOTA http://deeeet.com/writing/ 2014/07/30/golang-parallel-by-cpu/ ࣮ߦ͕ऴྃͨ͠ ͷͰड৴͢Δ ༰ྔ෼Λૹ৴ ͨ͠Β଴ͭ

Slide 12

Slide 12 text

Ϩδͷਓͱ෰ΛͨͨΉਓͷڠௐ w Ϩδͷਓ͕ྉۚΛܭࢉ͔ͯ͠Βɺ෰ΛͨͨΉॲཧΛ ෰ΛͨͨΉਓʹ΍ΒͤΔ • makeؔ਺ͷୈ2Ҿ਺Λ༩͑ͳ͚Ε͹༰ྔ͕0ͷνϟ ωϧ͕࡞ΕΔ(unbuffered channel) w ͓ۚΛ෷͏ॲཧͱ෰ΛંΓͨͨΉॲཧ͕྆ํऴ ྃˠϨδͷॲཧ͕ऴྃ w ˠ෰͕ͨͨΉॲཧ͕ऴΘΔͷΛνϟωϧΛ࢖ͬ ͯ଴ͭ w HPSPVUJOF͔Βߏ଄ମʹॻ͖ࠐΉؒʹɺࢀর͢Δͱ ڝ߹ঢ়ଶʹͳΔ w HPSPVUJOF͔Βείʔϓ֎ͷม਺ʹॻ͖ࠐΉࡍʹ ͸ඞͣϩοΫΛऔΓɺࢀর͞Εͳ͍Α͏ʹ͢Δ • sync.MutexͷϝιουLock() Unlock()Λ ࢖͏ͱͰ͖Δ ྉۚܭࢉ ෰ΛͨͨΉਓ ͷॲཧ ͜͜ʹ͕͔͔࣌ؒΔॲཧ ͓ۚΛࢧ෷͏ॲཧͱ ෰ΛͨͨΉॲཧͷ ྆ํ͕ऴྃͯ͠ Ϩδۀ຿ऴྃ

Slide 13

Slide 13 text

NBJOؔ਺ͷऴྃ • ดళ࣌ؒʹͳΔ·Ͱmainؔ਺Λऴྃͤ͞ͳ͍ • mainؔ਺͸HPSPVUJOFͷऴྃΛ଴ͨͳ͍ͷͰɺνϟ ωϧͳͲΛ࢖ͬͯऴྃ͠ͳ͍Α͏ʹ͢Δ • ͦ͏͠ͳ͍ͱ͙͢ʹऴྃ͢Δ • ຊདྷ͸ҟৗ࣌ʹ҆શʹดళͰ͖ΔΑ͏ʹ͢΂͖ • ࠓճ͸time.Sleep()Λͨ͠ • mainؔ਺͕ऴྃ͠ͳ͍ؒʹHPSPVUJOF಺ͷॲཧ͕ ૸Δ

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

·ͱΊ w ϢχΫϩͷϨδ͸٬ʢλεΫʣΛޮ཰ྑ͘ࡹ͘࢓૊Έ͕͋Δ w ٬ΛྻͰ؅ཧ w Ϩδۀ຿Λ઀٬ͱ෰ΛͨͨΉॲཧʹ෼ׂ w (PݴޠͷHPSPVUJOFͱνϟωϧ͸γϯϓϧͳϧʔϧ͔͠ͳ͍ ͕ɺͱͯ΋ύϫϑϧ w ޮ཰ྑ͘$16ͷίΞΛ࢖͍੾ΕΔίʔυΛॻ͚Δ w ࠓճͷίʔυ͸࣮ࡍͷιϑτ΢ΣΞͰ࢖͑Δ w ϢχΫϩͷϨδ͸ඇৗʹγεςϚνοΫͰޮ཰͕ྑ͍࢓૊Έ