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

ISUCON夏期講習2017 講義編 / isucon summer school 1

ISUCON夏期講習2017 講義編 / isucon summer school 1

Ca6281fff64797dc419b78f51f25c0a5?s=128

FUJIWARA Shunichiro
PRO

August 25, 2017
Tweet

Transcript

  1. ISUCON Նظߨश 2017 ߨٛฤ 2017.08.25 @fujiwara

  2. @fujiwara ٕज़෦ github.com/fujiwara sfujiwara.hatenablog.com

  3. ISUCON શઓ੷ ISUCON 1 - ༏উ (@songmu @sugyan) ISUCON 2

    - ༏উ (@songmu @typester) ! ISUCON 3 - ग़୊ ISUCON 4 - 3Ґ (@acidlemon @handlename) ISUCON 5 - ༏উ (@songmu @sugyan) ISUCON 6 - ४༏উ (@moshisora990 @kasari)
  4. ISUCON ͱ͸

  5. None
  6. ISUCON = Iikanjini Speed Up CONtest ༩͑ΒΕͨWebΞϓϦέʔγϣϯΛ ͋ΒΏΔखஈΛ΋ͬͯߴ଎Խ͢Δ ίϯςετ ϕϯνϚʔΫ͕࣮ߦ͞ΕɺͦͷείΞ͕ߴ͍νʔϜ͕উར

    OSͷઃఆมߋɺΞϓϦέʔγϣϯͷॻ͖׵͑ɺͳΜͰ΋OK ϕϯνϚʔΫ͕༗ޮͳείΞΛग़ͨ͠ == ੒ޭ
  7. ֓೦ਤ

  8. ISUCON ͷྺ࢙

  9. ISUCON 1,2 - ઌணॱຊબظ ༧બͳ͠ ઌணॱͰਃ͠ࠐΜͩνʔϜ͕ࢀՃͰ͖Δ (20νʔϜ) ISUCON 1 ༏উ৆ۚ10ສԁ

    ͓୊: blogͷίϝϯτཝ ग़୊: Livedoor1 ISUCON 2 ༏উ৆ۚ30ສԁ ͓୊: νέοτൢചαΠτ ग़୊: NHN Japan1 1 ͲͪΒ΋ݱ LINE
  10. ISUCON 3,4 - ༧બϩʔΧϧϕϯνظ ༧બɺֶੜ࿮͕Ͱ͖ͨ ༧બ͸ AWS ্ͷΠϯελϯεΛ֤νʔϜ͕1୆ىಈ ϕϯνϚʔΫ͸Πϯελϯε্ͷϓϩάϥϜ(Go੡όΠφϦ)͕ localhost

    ʹର࣮ͯ͠ߦ ISUCON 3 ༏উ৆ۚ100ສԁ(Ҏޙಉ͡) ͓୊: Nopaste / ը૾౤ߘSNS ग़୊: ΧϠοΫ ISUCON 4 ͓୊: ͍͢͜Μۜߦ / ಈը޿ࠂ഑৴ ग़୊: Cookpad
  11. ISUCON 3,4 ༧બ֓೦ਤ

  12. ISUCON 5,6 - ༧બϦϞʔτϕϯνظ ༧બ͸ GCP(5) Azure(6) ্ͷΠϯελϯεΛ֤͕ࣗىಈ ϕϯνϚʔΫ͸ӡӦ͕༻ҙͨ͠Πϯελϯε͕ ֤ࣗͷΠϯελϯεʹର࣮ͯ͠ߦ

    ISUCON 5 ͓୊: SNS(mixiతͳ) / ϚΠΫϩαʔϏε ग़୊: Treasure Data ISUCON 6 ͓୊: ΩʔϫʔυࣗಈϦϯΫ / ͓ֆ͔͖ڞ༗αΠτ ग़୊: ͸ͯͳ(༧બ) pixiv(ຊબ)
  13. None
  14. Ұൠ࿮ͷ༧બ௨աഒ཰͸15ഒҎ্ (16/267) ֶੜ࿮͸5ഒ (10/50) ຊબʹग़৔Ͱ͖Ε͹৆ۚ100ສԁ΋ເͰ͸ͳ͍ʂ

  15. ISUCON ࢀՃऀͷօ͞Μ(Ұൠ࿮) Webܥاۀʹ͓ۈΊ (͕ଟ͍) ೔ࠒ͔ΒڊେͳτϥϑΟοΫΛࡹ͍͍ͯΔ (ਓ΋͍Δ) ஶ໊ OSS ͷίϛολͱ͔ (كʹ͍Δ)

    νʔϜ͸৬৔Ͱ૊ΜͩΓɺ༑ਓͰ૊ΜͩΓ ΠϯϑϥدΓͷਓ͕ଟ͍ɺͱ͍͏͜ͱ΋ͳ͍
  16. ISUCON ͸૯߹֨ಆٕ OSɺϛυϧ΢ΣΞͷνϡʔχϯάͷΈͰ͸উͯͳ͍(ઈରʹ) ڝٕதͷ୹࣌ؒʹΞϓϦέʔγϣϯΛॻ͖׵͑ΔεΩϧ DB ͷ஌ࣝ ޮ཰ͷΑ͍ΞʔΩςΫνϟͷ஌ࣝ ϘτϧωοΫΛత֬ʹൃݟ͢Δೳྗ ຊબͰ͸ෳ਺୆ߏ੒ɺσϓϩΠ΋

  17. ͓͢͢Ίͷϝϯόʔߏ੒ OS΍ϛυϧ΢ΣΞʹڧ͍ਓ: 1໊ ΞϓϦέʔγϣϯʹڧ͍ਓ: 2໊ ϘτϧωοΫͷൃݟɺత֬ͳઃఆɺϞχλϦϯά͸ඞཁ ࣌ؒ഑෼ͱͯ͠଍Γͳ͍ͷ͸ΞϓϦέʔγϣϯͷॻ͖׵͑

  18. ISUCON Ͱ΍Δ͜ͱ = ύϑΥʔϚϯενϡʔχϯά

  19. ύϑΥʔϚϯενϡʔχϯά ISUCON ʹ͓͚ΔύϑΥʔϚϯε == ॲཧͨ͠HTTPϦΫΤετ਺ (جຊ) 2 Ұఆ࣌ؒ಺ʹͲΕ͚ͩଟ͘ͷHTTPϨεϙϯεΛฦͤΔ͔ 1ϦΫΤετ౰ͨΓͷॲཧ࣌ؒΛ୹͘͢Δ ฒߦͰଟ਺ͷϦΫΤετΛॲཧ͢Δ

    2 είΞͷܭࢉʹ͍ͭͯৄࡉ͸ϨΪϡϨʔγϣϯʹهࡌ͋Γ
  20. WebΞϓϦέʔγϣϯͷ֓೦ਤ ֤ཁૉͷॲཧΛ͍͔ʹগͳ͘͢Δ͔ ྫ: ੩తϑΝΠϧ͸WebαʔόͰ഑৴ (AppͰॲཧ͠ͳ͍) App͔ΒStorage΁ͷΫΤϦΛݮΒ ͢ StorageͰDiskΞΫηεΛݮΒ͢ ͦ΋ͦ΋ΫϥΠΞϯτ͔ΒϦΫΤε τͤ͞ͳ͍(Cache-Controlͱ͔)

  21. શϓϩάϥϚʔ͕஌Δ΂͖ϨΠςϯγʔ਺3 nano sec L1Ωϟογϡࢀর 0.5 ෼ذ༧ଌࣦഊ 5 L2Ωϟογϡࢀর 7 MutexͷϩοΫͱΞϯϩοΫ

    25 ϝΠϯϝϞϦʔࢀর 100 Zippy[Snappy]ʹΑΔ1KBͷѹॖ 3,000 1GbpsωοτϫʔΫӽ͠ʹ2KBΛૹ৴ 20,000 ϝϞϦʔ͔Β࿈ଓͨ͠1MBͷྖҬͷಡΈग़͠ 250,000 ಉҰσʔληϯλʔ಺ʹ͓͚Δϥ΢ϯυτϦοϓ 500,000 0.5 msec σΟεΫγʔΫ 10,000,000 10 msec σΟεΫ͔Β࿈ଓͨ͠1MBͷྖҬͷಡΈग़͠ 20,000,000 20 msec ύέοτΛΧϦϑΥϧχΞ→Φϥϯμ→ΧϦϑΥ ϧχΞͱૹΔ 150,000,000 150 msec 3 http://norvig.com/21-days.html#answers
  22. ͨͱ͑͹ TCP ͷ 3way handshake ઀ଓཱ֬·Ͱʹ 0.5ms x 1.5ճ =

    0.75ms
  23. ฒྻ౓Λ্͛ͯϨΠςϯγΛӅṭ͢Δ redis-benchmark -h $redis_server -c $c -t get

  24. ͨͱ͑͹ 1 HTTP ϦΫΤετΛ10msͰฦ٫͢Δ 1ճ͋ͨΓ ճ਺ ߹ܭ LL ͷ HTTP

    αʔόͰ Hello World 0.5ms 1 0.5ms ηογϣϯ؅ཧͷͨΊʹ Redis ʹΫΤϦ 0.5ms 1 0.5ms DBʹରͯ͠5ճΫΤϦΛൃߦ 1ms 5 5ms ςϯϓϨʔτΛϨϯμϦϯ ά 3ms 1 3ms 10 ms/req = 100 req/sec (1ฒྻ) ͪͳΈʹ ISUCON 1 ͷ༏উείΞ͸ 1500 req/sec ૬౰
  25. ۩ମతʹͲ͏͢Δ?

  26. ۩ମతʹͲ͏͢Δ? 1. ϘτϧωοΫΛݟ͚ͭΔ 2. ղফͯ͠ܭଌ͢Δ 3. (1,2Λ܁Γฦ͠) 4. ༏উ

  27. ϘτϧωοΫ Ұ൪ࡉ͍(஗͍)ͱ͜ΖΛվળ͠ͳ͍ͱҙຯ͕ͳ͍

  28. ଓ͖͸ ࣮ફฤ Ͱ

  29. TCP 3way handshake ը૾ग़య https://commons.wikimedia.org/wiki/File:Tcp_normal.svg