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

5分で導入!Failurewall で障害対策 / Failurewall - ScalaMa...

5分で導入!Failurewall で障害対策 / Failurewall - ScalaMatsuri 2016

ScalaMatsuri 2016 ランチタイム LT の発表資料です。
Scala 標準ライブラリの Future にリトライ機能や Circuit Breaker 機能を導入するライブラリ、Failurewall の紹介です。

https://2016.scalamatsuri.org/
https://github.com/failurewall/failurewall
https://qiita.com/okumin/items/d7a108ea36f3ad2e3882

okumin

July 03, 2019
Tweet

More Decks by okumin

Other Decks in Programming

Transcript

  1. ࢖͍ํ trait  HTTPClient  {      def  get(url:  String):  Future[HTTPResponse]

      }   val  client:  HTTPClient  =  ???   //  ԿΒ͔ͷΤϥʔॲཧΛߦ͏Failurewall   val  wall:  Failurewall[HTTPResponse,  HTTPResponse]  =  ???   val  actual:  Future[HTTPResponse]  =  wall.call  {      client.get("https://twitter.com/okumin")   }  
  2. Retry val  system  =  ActorSystem("mofu")   val  strategy  =  ExponentialBackoffStrategy(

         minBackoff  =  1.seconds,      maxBackoff  =  5.seconds   )   val  retry  =  AkkaRetryFailurewall[HTTPResponse](      maxTrialTimes  =  5,      strategy,      system.scheduler,      system.dispatcher   )  
  3. Semaphore val  executor:  ExecutionContext  =  ???   val  semaphore  =

     StdSemaphoreFailurewall[HTTPResponse](      permits  =  128,      executor   )  
  4. Circuit Breaker val  system  =  ActorSystem("mofu")   val  circuitBreaker  =

     AkkaCircuitBreakerFailurewall[HTTPResponse](      system.scheduler,      maxFailures  =  16,      callTimeout  =  5.seconds,      resetTimeout  =  10.seconds,      system.dispatcher   )  
  5. Composable ß  ΋͏Կ΋ා͘ͳ͍ val  retry:  Failurewall[HTTPResponse,  HTTPResponse]  =  ???  

    val  semaphore:  Failurewall[HTTPResponse,  HTTPResponse]  =  ???   val  circuitBreaker:  Failurewall[HTTPResponse,  HTTPResponse]  =  ???   circuitBreaker  compose  semaphore  compose  retry