サーキットブレーカーを導入しようとしている話

 サーキットブレーカーを導入しようとしている話

第2回 Nikotama.rb登壇資料です

E64bd0756a22bbbcbd5a7ce84c143628?s=128

yusuke miyazaki

June 18, 2019
Tweet

Transcript

  1. Re:valua t ion https://fril.jp/ L ead & Delight User F

    irst Ownership Fail Smart αʔΩοτϒϨʔΧʔΛಋೖ͠Α͏ͱ͍ͯ͠Δ࿩
  2. 3BLVNB4FSWJDF%FWFMPQNFOU(SPVQ 3BLVUFO JOD   :VTVLF.JZB[BLJ !ZTL@QSP !ZTL

  3. αʔΩοτϒϨʔΧʔͱ͸ʁ  

  4.   αʔΩοτϒϨʔΧʔͱ͸ʁ "1*Λར༻͢Δͱ͖ʹɺར༻͢Δ"1*ͷো֐͕ࣗ෼ͷ αʔϏε΁࿈࠯ͯ͠͠·Θͳ͍Α͏ʹ͢ΔͨΊͷ࢓૊Έ

  5.   αʔΩοτϒϨʔΧʔͱ͸ʁ ௨ৗ࣌ ࣗ෼ͷαʔϏε "1* ϦΫΤετ Ϩεϙϯε

  6.   αʔΩοτϒϨʔΧʔͱ͸ʁ "1*Ͱো֐͕ൃੜͨ࣌͠ ࣗ෼ͷαʔϏε "1* ϦΫΤετ Ԡ౴଴ͪͷϦΫΤετ͕૿Ճ͠ɺ ϦιʔεΛઐ༗ͨ݁͠Ռɺ "1*ͷো֐͕࿈࠯ͯ͠͠·͏͓ͦΕ͕͋Δ

  7.   αʔΩοτϒϨʔΧʔͱ͸ʁ "1*Ͱো֐͕ൃੜͨ࣌͠ ࣗ෼ͷαʔϏε "1* ϦΫΤετ Ԡ౴଴ͪͷϦΫΤετ͕૿Ճ͠ɺ ϦιʔεΛઐ༗ͨ݁͠Ռɺ "1*ͷো֐͕࿈࠯ͯ͠͠·͏͓ͦΕ͕͋Δ

  8. αʔΩοτ ϒϨʔΧʔ   αʔΩοτϒϨʔΧʔͱ͸ʁ ௨ৗ࣌ ࣗ෼ͷαʔϏε "1* ϦΫΤετ Ϩεϙϯε

    ϦΫΤετ Ϩεϙϯε
  9. αʔΩοτ ϒϨʔΧʔ   αʔΩοτϒϨʔΧʔͱ͸ʁ "1*Ͱো֐͕ൃੜͨ࣌͠ ࣗ෼ͷαʔϏε "1* 5JNFPVU ҟৗΛݕ஌͢Δͱɺ"1*ʹϦΫΤετ͢Δ͜ͱͳ͘ɺϨεϙϯεΛฦ͢

  10.   αʔΩοτϒϨʔΧʔͱ͸ʁ ͭͷϞʔυ͕ଘࡏ $-04&% ௨ৗϞʔυ 01&/ GBJMGBTUϞʔυ )"-'01&/ ෮چ֬ೝϞʔυ

    Τϥʔ਺͕ᮢ஋ಥഁ ࣌ؒܦա Τϥʔ͠ͳ͍͜ͱΛ֬ೝ Τϥʔͷঢ়گෆม
  11. αʔΩοτϒϨʔΧʔͷಋೖ  

  12.   αʔΩοτϒϨʔΧʔͷಋೖ ಋೖ͢Δํ๏ ಠࣗͰ࣮૷ (FNΛ࢖͏ 1SPT ΧελϚΠζࣗ༝ ࠷దͳ(FN͕͋Ε͹ɺ࣮૷͕ૣ͍ $POT

    ͕͔͔࣌ؒΔ ΧελϚΠζੑ͕ݶΒΕΔ (FN͕ϝϯςφϯε͞ΕΔ͔ෆ໌
  13.   αʔΩοτϒϨʔΧʔͷಋೖ ಋೖ͢Δํ๏ ಠࣗͰ࣮૷ (FNΛ࢖͏ 1SPT ΧελϚΠζࣗ༝ ࠷దͳ(FN͕͋Ε͹ɺ࣮૷͕ૣ͍ $POT

    ͕͔͔࣌ؒΔ ΧελϚΠζੑ͕ݶΒΕΔ (FN͕ϝϯςφϯε͞ΕΔ͔ෆ໌
  14.   αʔΩοτϒϨʔΧʔͷಋೖ (FNͷબఆ XTBSHFOUDJSDVJU@CSFBLFS ZBNNFSDJSDVJUCPY 4UBS   -BUFTUDPNNJU

      3&"%.&ͷॆ࣮౓ ˓ ˕
  15.   αʔΩοτϒϨʔΧʔͷಋೖ (FNͷબఆ XTBSHFOUDJSDVJU@CSFBLFS ZBNNFSDJSDVJUCPY 4UBS   -BUFTUDPNNJU

      3&"%.&ͷॆ࣮౓ ˓ ˕
  16.   αʔΩοτϒϨʔΧʔͷಋೖʙ(FNͷίΞ෦෼ def run if open? # ϩάग़ྗͳͲ else

    begin response = execution_timer.time(service, notifier, 'execution_time') do yield end success! # HALF-OPENͩͬͨ৔߹ɺCLOSEDʹ͢Δ rescue response = nil failure! # HALF_OPENͩͬͨ৔߹ɺOPENʹ / CLOSEDͩͬͨ৔߹ɺ৚݅ʹΑͬͯOPENʹ End end response end def http_get circuit.run do Zephyr.new('http://example.com').get('/api/messages') end end ˞͔ͳΓ؆ૉԽ͍ͯ͠·͢ɻࢀߟɿ(JU)VCͷ֘౰Օॴ
  17.   αʔΩοτϒϨʔΧʔͷಋೖʙ'BSBEBZͱ૊Έ߹Θ࣮ͤͨ૷ํ๏ require 'faraday' require 'circuitbox/faraday_middleware' conn = Faraday.new(:url

    => "http://example.com") do |c| c.use Circuitbox::FaradayMiddleware end response = conn.get("/api") if response.success? # success else # failure or open circuit end ˞3&"%.&͔Βͷൈਮ ˞'BSBEBZ͸ɺศརͳ)551ΫϥΠΞϯτϥΠϒϥϦʢ3VCZ,BJHJͰ΋঺հ͞Ε͍ͯ·ͨ͠ʣ
  18.   ࣮ࡍͷ࣮૷ɺϦϦʔε͸͜Ε͔Β 5P#FDPOUJOVFEʜ

  19. ·ͱΊ  

  20.   ·ͱΊ w αʔΩοτϒϨʔΧʔͱ͸ɺ"1*Λར༻͢Δͱ͖ʹɺ ར༻͢Δ"1*ͷো֐͕ࣗ෼ͷαʔϏε΁࿈࠯ͯ͠͠· Θͳ͍Α͏ʹ͢ΔͨΊͷ࢓૊Έ w (FN ZBNNFSDJSDVJUCPY

    Λ࢖ͬͯؾܰʹ࣮૷Ͱ ͖ͦ͏ w ࣍ճ͸ɺ࣮ࡍʹ࣮૷ͯ͠ϦϦʔεͨ͠ޙʹͲ͏ͩͬͨ ͔Λڞ༗͠·͢
  21.   ͋Γ͕ͱ͏͍͟͝·ͨ͠

  22. ิ଍  

  23.   ิ଍ w αʔΩοτϒϨʔΧʔͷ໊લͷ༝དྷ w αʔΩοτϒϨʔΧʔͱ͍͏ͷ͸ɺిؾճ࿏ͷϒ ϨʔΧʔͷ͜ͱʢࣄނ΍ނোͰେ͖ͳిྲྀ͕ྲྀΕͨ ͱ͖ʹࣗಈతʹःஅͯ͠഑ઢΛอޢ͢Δػߏͷ͜ ͱʣ

  24.   ิ଍ w ԿճΤϥʔͨ͠Β01&/ʹͳΔ͔ɺͳͲ͸ΧελϚΠ ζͰ͖Δ w σϑΥϧτ͸ɺ௚ۙϦΫΤετͰճҎ্Τϥʔ ͍ͯͨ͠Βɺ෼ؒ01&/ͱͳΔ w

    DJSDVJUCPYͷTUPSBHF Կճࣦഊ͔ͨ͠ͱ͔ ͸ɺ .POFUBͱ͍͏γϯϓϧͳLFZWBMVFTUPSFΛඪ४Ͱ ࢖༻͍ͯ͠Δ