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

ちょっといい感じの Ruby プロファイラがほしい (RubyKaigi 2023 follo...

osyoyu
August 19, 2023

ちょっといい感じの Ruby プロファイラがほしい (RubyKaigi 2023 follow up)

osyoyu

August 19, 2023
Tweet

More Decks by osyoyu

Other Decks in Technology

Transcript

  1. pp @osyoyu • /^͓͠ΐ[͏ʔ]Ώ/ • ࠷ۙͷ໨ඪ: ཮ւۭͷ੍೼ • ۙگ: ஍ٿͷ70%ΛΞϯϩοΫ͠·ͨ͠

    • ۭΛͲ͏߈ུ͢Δ͔ߟ͍͑ͯ·͢ • ඈߦػ͔ɺϋϯάάϥΠμʔతͳͷ͔
  2. ͓͞Β͍: Ϟνϕʔγϣϯ • ISUCON Ͱ༏উ͢ΔͨΊʹɺRuby ϓϩάϥϜͷϘτϧωοΫΛ
 ޮ཰తʹ୳͔ͨͬͨ͠ • ॳݟͷʢͱͯ΋஗͍ʣWeb ΞϓϦέʔγϣϯΛ౉͞Εͯ

    • ੍ݶ࣌ؒ8࣌ؒͰύϑΥʔϚϯενϡʔχϯά͍ͯͩ͘͠͞ • ͱ͍͏ڝٕ͕͋ͬͯɺRuby Ͱউ͍ͪͨ • ͦͷͨΊʹ Ruby ͷྑ͍ϓϩϑΝΠϥ͕΄͍͠
  3. ϓϩϑΝΠϧࣗମ • Process/Thread ୯ҐͰऩूͯ͠ɺͦΕͧΕͷ࢓ࣄͿΓΛݟ͍ͨ • طଘͷ API (rb_pro fi le_frames())

    ͸ GVL Λ͍࣋ͬͯΔ Thread ͷ
 ͜ͱ͚ͩڭ͑ͯ͘ΕΔ • ೚ҙͷ Thread ͷ৘ใΛऔΕΔ৽ API ΛೖΕ͍ͨ (ruby/ruby#7784) • CPU Λ࢖ͬͯΔ࣌ؒɺI/O ʹ࢖ͬͯΔ࣌ؒΛਖ਼֬ʹ೺Ѳ͍ͨ͠ • Ruby 3.2 Ͱೖͬͨ hook (RUBY_INTERNAL_THREAD_EVENT_*) ͰͱΕΔ Ruby ʹඞཁͳػೳΛ଍͍ͯ͘͠
  4. ϓϩϑΝΠϥΛࢼ࡞ͯ͠Έ͍ͯ·͢ https://github.com/osyoyu/pf2 • ໨ඪ͸ʮ৘ใΛͰ͖Δ͚ͩू໿Ͱ͖ΔϓϩϑΝΠϥʯ • ϓϩϑΝΠϦϯά෦͸ rb_pro fi le_frames() API

    Λͪΐͬͱ֦ு • (rb_thread_pro fi le_frames() (ruby/ruby#7784) ͕ͳ͍طଘͷ Ruby Ͱ͸ಈ͖·ͤΜ…… ͳͷͰϦϦʔεͯ͠·ͤΜ……) • ϏδϡΞϥΠβʹ͸ Firefox Pro fi ler Λ࠾༻
  5. ྫ୊: Ϛϯσϧϒϩू߹Λฒྻܭࢉ • ڻҟతฒྻԽՄೳ (embarrassingly parallell) Β͍͠ • σʔλͷड͚౉͠ͱ͔͠ͳ͍͍ͯ͘ •

    ΞϜμʔϧઌੜ׻ت • ͔͠͠ݱ࣮͸ • 1 thread 148.04 seconds 16 threads 147.94 seconds
  6. Future work • ϦϦʔε • GitHub ʹ͸ҰԠஔ͍ͯΔ͚Ͳɺruby master Ͱ΋ϏϧυͰ͖·ͤΜ •

    rb_thread_pro fi le_frames() (ruby/ruby#7784) Λ
 Ϛʔδ·Ͱ΋͍͔ͬͯͳ͍ͱ͍͚ͳ͍ • ศརͳػೳͷ௥Ճ • ೚ҙͷλΠϛϯάͰϚʔΧʔΛଧͯΔػೳ • ϒϥ΢βͷ User Timings API (performance.mark) తͳΠϝʔδ • ͍͍ػೳืूத • Stackprof Ҏ֎ʹ΋༗ྗͳϓϩϑΝΠϥ͸طʹ͍͔ͭ͋͘ΔͷͰɺ
 ৽͍͠ͷͱͯ͠ग़͢΂͖͔͸΍΍ߟ͍͑ͯΔ……