Linuxコマンドでボトルネックを調べる

 Linuxコマンドでボトルネックを調べる

俺の話を聞け!!LT大会 #8でトークした資料です

1b838da2065660793d5b26f2cdc32de7?s=128

Kazuhiko Yamashita

March 20, 2018
Tweet

Transcript

  1. ʙय़ͩʂՖคͩʂ-5େձͩ͊͊͊͋͋͋͋ʂʂʂ̍ʙ !QZBNB(.01FQBCP *OD Զͷ࿩Λฉ͚ʂʂ-5େձ -JOVYίϚϯυͰϘτϧωοΫ Λௐ΂Δ

  2. ϗεςΟϯάࣄۀ෦νʔϑςΫχΧϧϦʔυ  ࢁԼ࿨඙!QZBNB

  3. ϖύϘ෱Ԭ

  4. αʔόαΠυɺϑϩϯτΤϯυɺ ΠϯϑϥΤϯδχΞશһདྷͯ͘Εʂʂʂʂ̍ ࠷৽ͷ࠾༻৘ใΛνΣοΫˠ !QC@SFDSVJU

  5. Ϙτϧωο Ϋௐࠪ

  6. ʮͳΜ͔Θ͔ΒΜ͚Ͳɺ Կ͔͕஗ͯ͘ ॲཧ͕ॏ͍ʯ

  7. ಄ѱͦ͏

  8. ύϑΥʔϚϯεղੳʹ͸ ͍͔ͭ͘ͷखஈ͕͋Δ

  9. ͳΜ͔͍͍ͩͨͲͷձࣾʹ΋͍Δ͍͢͝ਓʹฉ͘ w͍͢͝ਓʹฉ͘ͱɺ͍͍ͩͨղܾͯ͘͠ΕΔ w͍͢͝ਓ͸͍͢͝ͷͰɺͦͷ৔ͰΘ͔Βͳͯ͘΋ɺ͍͍ͩͨ࣍ͷ೔ʹ
 ʮࡢ೔ͷ͋ΕΘ͔ͬͨΑʂʂʂʯͱ͔ௐ΂͖ͯͯ͘ΕΔ w͍͢͝ਓʹฉ͘ͱɺ͍͢͝ਓ͕ؤுΔ͚ͩͰɺࣗ෼͕ؤுΒͳ͍͔Β ࣗ෼͕੒௕͠ͳ͍

  10. ϓϩϑΝΠϦϯά wIUUQTHJUIVCDPNUNNTUBDLQSPG ݴޠ໊ϓϩϑΝΠϥ<ݕࡧ>

  11. -JOVYͷίϚϯυͰௐ΂Δ wHEC5IF(/6%FCVHHFS wTUSBDF5SBDFTZTUFNDBMMTBOETJHOBMT wQFSG1FSGPSNBODFBOBMZTJTUPPMTGPS-JOVY wWBMHSJOEBTVJUFPGUPPMTGPSEFCVHHJOHBOEQSPpMJOHQSPHSBNT

  12. ࣄྫ

  13. NSVCZͷ"1*ΞΫηε͕཯଎ NSVCZ DMJFOU "1*4FSWFS SFTPVSDFFYBNQMF NSVCZͷ$MJFOU͔Β͋Δ"1*Λ࣮ߦͯ͠ .#ͷϨεϙϯεΛऔಘ͢Δ৔߹ +40/

  14. ࣄྫ ॠؒతʹ(CZUF͘Β͍ ϝϞϦ࢖͏

  15. WBMHSJOEͰϝϞϦͷΞϩέʔγϣϯΛݟΔ # valgrind curl http://localhost/resource/example > /dev/null … ==18619== HEAP

    SUMMARY: ==18619== in use at exit: 0 bytes in 0 blocks ==18619== total heap usage: 1,863 allocs, 1,863 frees, 211,125 bytes allocated # valgrind /home/pyama/mruby test.rb … ==12811== HEAP SUMMARY: ==12811== in use at exit: 0 bytes in 0 blocks ==12811== total heap usage: 51,721 allocs, 51,721 frees, 12,028,345,116 bytes allocated
  16. ʗ ?P? ʘ(

  17. TUSBDFͰγεςϜίʔϧͷ౷ܭΛऔΔ # strace -fc /home/pyama/mruby test.rb % time seconds usecs/call

    calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 73.00 0.006317 2 3361 munmap 23.27 0.002014 11 183 brk 2.62 0.000227 0 1734 read 1.11 0.000096 0 3380 mmap 0.00 0.000000 0 3 write 0.00 0.000000 0 16 open 0.00 0.000000 0 23 close NVONBQ͕ࢧ഑త IUUQTMJOVYKNPTEOKQIUNM-%1@NBOQBHFTNBONNBQIUNM
  18. QFSGΛར༻ͯ͠ίʔϧάϥϑΛऔಘ͢Δ IUUQNSVCZPSHEPDTBQJIFBEFSTNSVCZ@'TUSJOHIIUNMNSC@TUS@QMVTGVODUJPO # perf record --call-graph dwarf -- /home/pyama/mruby test.rb

    # perf report -g -G —stdio 94.35% 0.03% mruby mruby [.] mrb_str_plus | ---mrb_str_plus | --20.06%-- mrb_vm_exec mrb_vm_run … NSC@TUS@QMVT͕ࢧ഑త
  19. ৘ใ͔ΒԾઆΛཱͯΔ wॲཧ͸)551ϦΫΤετͰϨεϙϯεϘσΟ͸αΠζ͕େ͖͍ wϝϞϦ(#࢖ͬͯΔΦϫλ wNVONBQ͕ࢧ഑తͰճ਺΋ଟ͍͜ͱ͔ΒɺϝϞϦͷ֬อɺղ์͕ଟ ͍ͷͰ͸ͳ͍͔ʁ wNSC@TUS@QMVT͕ࢧ഑తͰ͋Δ͜ͱ͔Βɺจࣈྻ݁߹͕ଟ͍͜ͱ͕ݪ ҼͬΆ͍ͳʁ NSC@TUS@QMVTSVCZFbDlBz lCz`

  20. ΧΫΧΫ γΧδΧ

  21. ݪҼ͸)551ϦΫΤετͷόοϑΝαΠζ IUUQTHJUIVCDPNNBUTVNPUPSZNSVCZTJNQMFIUUQQVMM NSVCZ DMJFOU "1*4FSWFS SFTPVSDFFYBNQMF +40/ ιέοτ͔Β+40/Λड͚औΔࡍͷόοϑΝαΠζ͕CZUFͰ͋ͬͨ͜ͱ͔Βɺ ಡࠐͷϧʔϓճ਺͕ଟ͘ͳ͍ͬͯͨɻόοϑΝͷαΠζΛCZUF΁มߋ͢Δ͜ͱͰ ݁Ռͱͯ͠ϧʔϓճ਺ΛݮΒͯ͠จࣈྻ݁߹ͷճ਺ΛݮΒͨ͠

         
  22. NSVCZTJNQMFIUUQ while (t = socket.read(1024)) if block_given? yield t next

    end ɹ #όοϑΝ͕গͳ͍ͱϧʔϓճ਺͕૿͑ͯɺ݁߹ճ਺͕૿͑ͯແବʹϝϞϦ֬อ response_text += t end ͔͠΋ɺ($͕૸Δ·Ͱ͸։์͞Εͳ͍
  23. ΋͏Ұา ౿ΈࠐΉ

  24. NSC@TUS@QMVT NSVCZͰ͸จࣈྻ݁߹ͷࡍʹ݁߹݁Ռจࣈྻͷ ϝϞϦΛ֬อ͢Δ

  25. NSVCZTJNQMFIUUQ while (t = socket.read(1024)) if block_given? yield t next

    end response_text << t end ͞ΒʹDPODBUʹ͢Δ͜ͱͰɺແବͳྖҬ֬อΛ΍ΊΔ
  26. NSC@TUS@QMVT74NSC@TUS@DBU TUSJOHlBCz TUSJOHlBz TUSJOHlCz TUSJOHlBz TUSJOHlCz  TUSJOHlBz TUSJOHlCz 

    TUSJOHlBCz 
  27. IUUQTUFOTOBQPODPNBSDIJWFT

  28. ·ͱΊ wϓϩϑΝΠϥ΍ίϚϯυΛར༻ͯ͠৘ใΛूΊΑ͏ wूΊͨ৘ใ͔ΒԾઆΛཱͯΑ͏ wԾઆΛݕূ͠Α͏ wσόοάίʔυͰ͋Ε͜Εࢼ͢ wਂ͘ίʔυΛಡΉɺ࣮૷ʹഭΔ

  29. 5IBOLZPV ࠷৽ͷ࠾༻৘ใΛνΣοΫˠ !QC@SFDSVJU