Skip to content

Commit c381d9f

Browse files
author
guyplusplus
committed
Log sample for maxDurationOpenInHalfOpenState
1 parent ec393a7 commit c381d9f

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

README.md

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ loop
4545

4646
**Important**: `callSucceeded()` or `callFailed()` must always be invoked after `isClosedForThisCall()`. Otherwise breaker in HALF-OPEN state will never move to another state, waiting for the results of the permittedNumberOfCallsInHalfOpenState calls.
4747

48-
To avoid this situation a new property maxDurationOpenInHalfOpenState is introduced. In HALF-OPEN state, after permittedNumberOfCallsInHalfOpenState calls (`isClosedForThisCall()` returns true), all its subsequent calls (`isClosedForThisCall()` returns false) won't be executed as the circuit is opened. If this situation lasts longer than maxDurationOpenInHalfOpenState ms, the breaker goes back automatically to the CLOSED state.
48+
To avoid this situation a new property called maxDurationOpenInHalfOpenState is introduced. In HALF-OPEN state, after permittedNumberOfCallsInHalfOpenState calls (`isClosedForThisCall()` returns true), all its subsequent calls (`isClosedForThisCall()` returns false) should not be executed as the circuit is opened. If this situation lasts longer than maxDurationOpenInHalfOpenState ms, the breaker goes back automatically to the CLOSED state.
4949

5050
## Circuit Breaker Configuration using Properties
5151
The circuit breaker can easily be configured using `java.util.Properties`, possibly adding prefix, for example:
@@ -66,8 +66,14 @@ SVC1.failureRateThreshold=20
6666
SVC1.slidingWindowSize=150
6767
```
6868

69-
## Log File
70-
Log file contains information about the breaker state change as well as reason. Here is simple content. Log monitoring can be used to capture events.
69+
## Concurrency
70+
The code has 3 synchronized methods, it has minimum impact to initial code performance. Actual business logic is not included in the synchronized code, so blocking time is minimum
71+
- `boolean isClosedForThisCall()` to check the state of the breaker for this current call
72+
- `void callFailed(long callDuration)` to inform the breaker that the call failed
73+
- `void callSucceeded(long callDuration)` to inform the breaker that the call succeeded
74+
75+
## Log File Output
76+
Log file contains information about the breaker state change as well as the reason and simple statistics. Here is simple content. Log monitoring can be used to capture events.
7177

7278
```
7379
Mar. 07, 2020 6:56:21 PM com.geckotechnology.simpleCircuitBreaker.CircuitBreakerConfig logInfoConfigProperties
@@ -118,8 +124,30 @@ INFO: Breaker state changed to: CLOSED
118124
...
119125
```
120126

121-
## Concurrency
122-
The code has 3 synchronized methods, it has minimum impact to initial code performance. Actual business logic is not included in the synchronized code, so blocking time is minimum
123-
- `boolean isClosedForThisCall()` to check the state of the breaker for this current call
124-
- `void callFailed(long callDuration)` to inform the breaker that the call failed
125-
- `void callSucceeded(long callDuration)` to inform the breaker that the call succeeded
127+
Another example showing the behavior of maxDurationOpenInHalfOpenState.
128+
129+
```
130+
...
131+
...
132+
Mar. 08, 2020 5:02:27 PM com.geckotechnology.simpleCircuitBreaker.CircuitBreaker moveToClosedState
133+
INFO: Breaker state changed to: CLOSED
134+
...
135+
...
136+
Mar. 08, 2020 5:02:52 PM com.geckotechnology.simpleCircuitBreaker.CircuitBreaker isExceedFailureOrSlowRateThreshold
137+
WARNING: High slowCallRate: 45.299145%, slowCallDurationCount: 53, callCount: 117
138+
Mar. 08, 2020 5:02:52 PM com.geckotechnology.simpleCircuitBreaker.CircuitBreaker moveToOpenState
139+
INFO: Breaker state changed to: OPEN
140+
...
141+
...
142+
Mar. 08, 2020 5:02:54 PM com.geckotechnology.simpleCircuitBreaker.CircuitBreaker moveToHalfOpenState
143+
INFO: Breaker state changed to: HALF_OPEN
144+
...
145+
...
146+
Mar. 08, 2020 5:02:55 PM com.geckotechnology.simpleCircuitBreaker.BreakerHalfOpenState isClosedForThisCall
147+
WARNING: maxDurationOpenInHalfOpenState is reached. CallCount: 4, failureCallCount: 1, slowCallDurationCount: 1
148+
Mar. 08, 2020 5:02:55 PM com.geckotechnology.simpleCircuitBreaker.CircuitBreaker moveToClosedState
149+
INFO: Breaker state changed to: CLOSED
150+
...
151+
...
152+
```
153+

0 commit comments

Comments
 (0)