Skip to content

jufab/hystrix-resilience4j-microprofile-fault-tolerance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hystrix - Resilience4j - Microprofile Fault Tolerance

This repository contains a test around implementation of resilience and (for the moment) around Circuit breaker.

I use 3 libraries, and I want to see implementation, configuration, complexity and result.

To help me (and for my curiosity of course ^_^), I use microprofile starter to initialise all this project.

Table of Contents

Context

This is a test around this 3 libraries

For the moment, I only use the "Circuit Breaker".

Microprofile Starter

To initialise the project, I use Microprofile starter with this configuration

  • MP 3.3
  • JDK 11
  • Wildfly

About Wildfly Jar

Version 1.0.0.Alpha4 (include in MP Starter)

more information about this maven plugin

Projects

Each folder contains circuit breaker library :

You need

  • JDK 11
  • Maven 3.6.X

Run it

Start Maven command

mvn clean package wildfly-jar:run

API

Every project run on http://localhost:8080

Project path

Endpoints

Every project expose 2 endpoints :

Circuit Breaker configuration

Every project have the same configuration :

  • Request Volume Threshold (or Minimum Number Of Calls) : 4
  • Error Threshold Percentage (or failure Rate Threshold) : 50%
  • Sleep Window (or Wait Duration In Open State or Delay) (Duration) : 5 seconds

So, If there are 2 errors on 4 requests (50%), circuit breaker is open during 5 seconds.

At first try, there are 4 requests before trigger the circuit breaker...

Request Volume Threshold

You have circuit breaker between your api exposed and an external API (or an other service/database/etc...)

Suppose that Request Volume Threshold have a value of 2, the sequence is :

This a sequence diagram to help to understand the Request Volume Threshold (or minimum number of calls for Resilience4j)

Request Volume Threshold

Circuit breaker open after 2 errors : we suppose Error Threshold Percentage have a value of 100%

plantuml

Error Threshold Percentage

This configuration is the percentage of error before circuit breaker open.

So, 50% of 4 Request Volume Threshold, the circuit breaker open after 2 errors.

Sleep Window

It's time during circuit breaker is Open and wait to Close (or Half Open).

This schema from Resilience4j resume this state :

state machine

If you make call during this time, you have an exception by the circuit breaker.

After this time, circuit breaker closed

With previous sequence and a value of 5 seconds :

sleep window

plantuml

Bonus Resilience4j - Slow Call Rate Threshold and Slow Call Duration Threshold

After advice of Robert Winkler (@rbrtwnklr) on Twitter, I try this two configurations.

  • Slow Call Duration Threshold define time of a slow call (default 60000 ms)
  • Slow Call Rate Threshold is a percent value (value between 0 to 100 default 100). it's calculate with the minimumNumberOfCalls value and the number of slow call

For example, we have this configuration :

  • minimumNumberOfCalls = 4
  • slowCallRateThreshold = 25%
  • slowCallDurationThreshold = 3 secondes

And there is no error during call (we have a response) but just a slow call...

plantuml

plantuml

Circuit Breaker is now open because we have 25% (slowCallRateThreshold) of 4 calls (minimumNumberOfCalls) greater than 3 secondes (slowCallDurationThreshold)

Sleep Window reset circuit breaker state (open to close)...

Circuit breaker Results

Hystrix

In exception endpoint

  • Circuit breaker close : expose an HystrixException with a BadRequestException cause
  • Circuit breaker open : expose an HystrixException with a RuntimeException cause

Resilience4j

In exception endpoint

  • Circuit breaker close : expose a BadRequestException
  • Circuit breaker open : expose a CallNotPermittedException

Microprofile fault tolerance

In exception endpoint

  • Circuit breaker close : expose a BadRequestException
  • Circuit breaker open : expose a CircuitBreakerOpenException

Unit Tests

Try to test with a unit test circuit breaker (for example in case of fallback?)

Hystrix

Can forceOpen programmatically

see here

Resilience4j

Can forceOpen programmatically

see here

Microprofile fault tolerance

No unit test for the circuit breaker : only on integration test (Not Implemented)

to be continued...

About

Test / Lab Around Hystrix, Resilience4j and Microprofile Fault Tolerance

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published