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

〇〇を切り出したいときに / Extract something from big rails app

〇〇を切り出したいときに / Extract something from big rails app

TokyuRuby会議12 での飛び入り LT 資料です
http://regional.rubykaigi.org/tokyu12/

9eed44f137609e6ce3b6f1e14f80b9e1?s=128

Masayuki Izumi

July 29, 2018
Tweet

Transcript

  1. ʓʓΛ੾Γग़͍ͨ͠ͱ͖ʹ ͓͓͖ΊͷϦϑΝΫλΛ΍ΔPO3BJMTʢʁʣ TokyuRubyKaigi #12 !J[VNJO 2018.7.29 -

  2. izumin5210 Engineer at Wantedly, Inc. Wantedly People ‣ Web Application

    Engineer - Profile Data Strategy Group ‣ Interests in developer productivity on microservices Gopher, Rubyist, JavaScripter and Androider
  3. ˓˓Λ੾Γग़͍ͨ͠ɾҠߦ͍ͨ͠ ࢖͍·Θͤͦ͏ͳ࣮૷ %# .PEFM ػೳ γεςϜͷҰ෦ 

  4.  ςετΛॻ͜͏  ϩάΛͱΖ͏ ͍͞͠ΐʹߟ͑Δ͜ͱ

  5.  ςετΛॻ͜͏  ͦ΋ͦ΋ςετ͸ϦϑΝΫλϦϯάͷͨΊʹ͋Δʢۃ࿦ʣ  ίʔυ͕յΕΔͱςετ͕མͪͯؾ͚ͮͯศར  ͳ͔ͬͨΒؤுͬͯॻ͘ʢن໛ʹΑͬͯ͸ఘΊ΋؊৺ʣ  ϩάΛͱΖ͏

    ͍͞͠ΐʹߟ͑Δ͜ͱ
  6.  ςετΛॻ͜͏  ϩάΛͱΖ͏  Ͳ͏͍͏ܦ࿏Ͱར༻͞ΕΔ͔ɼͲΕ͘Β͍ར༻͞ΕΔ͔  ͦ΋ͦ΋ESPQͰ͖ͳ͍͔  յΕͦ͏ͳͱ͜ΖͷςετΛॏ఺తʹॻ͚Δ

    ͍͞͠ΐʹߟ͑Δ͜ͱ
  7.  DBMMFSΛه࿥͢Δ  ࡶʹϩάΛཷΊࠐΊΔπʔϧɾαʔϏεΛ࢖͏ ƁŞƄŪžUJQT

  8.  DBMMFSΛه࿥͢Δ  ͡  `Thread.current[:controller] = controller_name`͠ͱ͘ͱศར  ͋͘·ͰҰ࣌తͳϩάऩूͳͷͰɼਖ਼͠͞खܰ͞ɾརศੑ

     ࡶʹϩάΛཷΊࠐΊΔπʔϧɾαʔϏεΛ࢖͏ ƁŞƄŪžUJQT caller.find do |c| !c.to_s.start_with?(Bundler.bundle_path.to_s) && c.to_s.start_with?(Rails.root.to_s) end
  9.  DBMMFSΛه࿥͢Δ  ࡶʹϩάΛཷΊࠐΊΔπʔϧɾαʔϏεΛ࢖͏  ʮϨεϙϯεʹӨڹΛ༩͑ͳ͍ʯ͸ॏཁ  ͍͍ײ͡ʹCVGGFSJOHͨ͠ΓඇಉظͰσʔλૹͬͯ͘ΕΔ܅Λ͔ͭ͏  fluent-logger-ruby

    td-logger-ruby FUD  Ұ࣌తͳϩάऩूͳͷͰɼਖ਼͠͞खܰ͞ɾརศੑେ੾ͳ͜ͱͳͷͰʢ͈́ ƁŞƄŪžUJQT
  10.  DBMMFSΛه࿥͢Δ  ࡶʹϩάΛཷΊࠐΊΔπʔϧɾαʔϏεΛ࢖͏  ʮϨεϙϯεʹӨڹΛ༩͑ͳ͍ʯ͸ॏཁ  ͍͍ײ͡ʹCVGGFSJOHͨ͠ΓඇಉظͰσʔλૹͬͯ͘ΕΔ܅Λ͔ͭ͏  qVFOUMPHHFSSVCZ

    UEMPHHFSSVCZ FUD  Ұ࣌తͳϩάऩूͳͷͰɼਖ਼͠͞खܰ͞ɾརศੑେ੾ͳ͜ͱͳͷͰʢ͈́ ƁŞƄŪžUJQT caller_app = caller.find do |c| !c.to_s.start_with?(Bundler.bundle_path.to_s) && c.to_s.start_with?(Rails.root.to_s) end TD.event.post("hoge_log", { caller_app: caller_app, request_controller: Tread.current[:request_controller], request_action: Tread.current[:request_action], # sinp. }) Կ΋ߟ͑ͣʢUFTUBCJMJUZʹӨڹΛ༩͑ͣʣɼࡶʹϩά౤͛ΒΕΔͷ͸3VCZ͔ͩΒͦ͜
  11.  DBMMFSΛه࿥͢Δ  ࡶʹϩάΛཷΊࠐΊΔπʔϧɾαʔϏεΛ࢖͏  ʮϨεϙϯεʹӨڹΛ༩͑ͳ͍ʯ͸ॏཁ  ͍͍ײ͡ʹCVGGFSJOHͨ͠ΓඇಉظͰσʔλૹͬͯ͘ΕΔ܅Λ͔ͭ͏  qVFOUMPHHFSSVCZ

    UEMPHHFSSVCZ FUD  Ұ࣌తͳϩάऩूͳͷͰɼਖ਼͠͞खܰ͞ɾརศੑେ੾ͳ͜ͱͳͷͰʢ͈́ ƁŞƄŪžUJQT class ActiveRecrod::Relation def eager_loading? super.tap do |loading| if loading # send logs end end end 3VCZͳͷͰܭଌ༻ίʔυ͸Ͳ͜ʹͰ΋࢓ࠐΊΔ ʢ˞༻͕ࡁΜͩΒফ͠·͠ΐ͏ʣ
  12.  ίʔυͷมߋൣғΛ࠷খʹཹΊΔ  Ϛϝʹຊ൪ʹग़͢  ෳࡶͳͱ͜Ζ͸࡟Εͳ͍͔ৄ͍͠ਓʹฉ͘ Ͳ͏΍ͬͯ͢͢ΊΔʁ

  13.  ίʔυͷมߋൣғΛ࠷খʹཹΊΔ  ΞϓϦ͕σΧ͘ͳΔͱ໢ཏతʹมߋ͢Δͷ͸େม  FH%#෼ׂͰAProfileA͕AProfileDb::ProfileAʹͳΓ·͢ͱ͔มߋྔଟ͗ͯ͢ແཧ  ϕʔεΫϥεΛม͑ΔʢAApplicationRecordAAProfileRecordAʣͱ͔ͳΒ·ͩΘ͔Δ  ӨڹൣғΛࡶʹ೺Ѳ͢ΔͷʹΫϥεਤॻ͘ͱศར

     Ϛϝʹຊ൪ʹग़͢  ෳࡶͳͱ͜Ζ͸࡟Εͳ͍͔ৄ͍͠ਓʹฉ͘ Ͳ͏΍ͬͯ͢͢ΊΔʁ
  14.  ίʔυͷมߋൣғΛ࠷খʹཹΊΔ  ΞϓϦ͕σΧ͘ͳΔͱ໢ཏతʹมߋ͢Δͷ͸େม  FH%#෼ׂͰAProfileA͕AProfileDb::ProfileAʹͳΓ·͢ͱ͔มߋྔଟ͗ͯ͢ແཧ  ϕʔεΫϥεΛม͑ΔʢAApplicationRecordAAProfileRecordAʣͱ͔ͳΒ·ͩΘ͔Δ  ӨڹൣғΛࡶʹ೺Ѳ͢ΔͷʹΫϥεਤॻ͘ͱศར

     Ϛϝʹຊ൪ʹग़͢  ෳࡶͳͱ͜Ζ͸࡟Εͳ͍͔ৄ͍͠ਓʹฉ͘ Ͳ͏΍ͬͯ͢͢ΊΔʁ ػցతʹੜ੒Ͱ͖Δؾ΋͢Δ͕ɼͲΕ͘Β͍3VCZͷຐज़Λ࢖ͬͯΔ͔ʹґଘ͢Δ ˢͷΫϥεਤ͸໨HSFQ
  15.  ίʔυͷมߋൣғΛ࠷খʹཹΊΔ  Ϛϝʹຊ൪ʹग़͢  Ұؾʹ΍ΔͱյΕͨͱ͖ʹݪҼڀ໌͕େม  ෳࡶͳͱ͜Ζ͸࡟Εͳ͍͔ৄ͍͠ਓʹฉ͘ Ͳ͏΍ͬͯ͢͢ΊΔʁ

  16.  ίʔυͷมߋൣғΛ࠷খʹཹΊΔ  Ϛϝʹຊ൪ʹग़͢  ෳࡶͳͱ͜Ζ͸࡟Εͳ͍͔ৄ͍͠ਓʹฉ͘  ͨ·ʔʹʮ͜ΜͳΜઈରແཧ΍Ζ͆ʯΈ͍ͨͳͷ͕͋Δ  ΊͬͪΌ"SFM͝ʹΐ͝ʹΐͯ͠Δͱ͔ɼΞϓϦͷίΞʹΊͬͪΌґଘͯ͠Δͱ͔

     ͦ͏͍͏ͷ͸ͦ΋ͦ΋࢓༷Λ࡟Εͳ͍͔ɾଞͷ࣮૷͕ͳ͍͔ߟ͑Δ  υϝΠϯʹৄ͍͠ਓʹ΍ͬͯ΋Β͏ͷ͕٢ Ͳ͏΍ͬͯ͢͢ΊΔʁ
  17. ͍ͪ͹ΜॏཁͳϙΠϯτ ʢݸਓతʹʣ

  18. ੎͍ͱے೑Ͱԡ͠੾Δ ௕ظઓʹͳΔͱ৺͕ંΕͦ͏ʹͳΔ ˞͜ͷͱ͖ʢ%#෼ׂʣ͸਺೔Ͱڧߦಥഁͨ͠ͷͰ͔͢ΓইͰࡁΜͩ

  19. ࣮ࡍʹͦͦ͜͜Ͱ͔͍ΞϓϦͰ΍ͬͨࣄྫ

  20. ࣮ࡍʹͦͦ͜͜Ͱ͔͍ΞϓϦͰ΍ͬͨࣄྫ ͜͜ʹه͢ʹ͸༨ന͕ڱ͗͢Δ

  21. None
  22. ͖ͭͮ͸ Ͱʂ