sequence
This paper focuses on the DefaultHealthChecker of Dubo-Go
DefaultHealthChecker
Dubbo – go – v1.4.2 / cluster/router/healthcheck/default_health_check. Go
func init() { extension.SethealthChecker(constant.DEFAULT_HEALTH_CHECKER, NewDefaultHealthChecker) } // DefaultHealthChecker is the default implementation of HealthChecker, which determines the health status of // the invoker based on the number of successive bad request and the current active request. type DefaultHealthChecker struct { // the limit of outstanding request outStandingRequestConutLimit int32 // the threshold of successive-failure-request requestSuccessiveFailureThreshold int32 // value of circuit-tripped timeout factor circuitTrippedTimeoutFactor int32 }Copy the code
- DefaultHealthChecker defines outStandingRequestConutLimit, requestSuccessiveFailureThreshold, circuitTrippedTimeoutFactor properties
NewDefaultHealthChecker
Dubbo – go – v1.4.2 / cluster/router/healthcheck/default_health_check. Go
// NewDefaultHealthChecker constructs a new DefaultHealthChecker based on the url func NewDefaultHealthChecker(url *common.URL) router.HealthChecker { return &DefaultHealthChecker{ outStandingRequestConutLimit: int32(url.GetParamInt(constant.OUTSTANDING_REQUEST_COUNT_LIMIT_KEY, math.MaxInt32)), requestSuccessiveFailureThreshold: int32(url.GetParamInt(constant.SUCCESSIVE_FAILED_REQUEST_THRESHOLD_KEY, constant.DEFAULT_SUCCESSIVE_FAILED_REQUEST_MAX_DIFF)), circuitTrippedTimeoutFactor: int32(url.GetParamInt(constant.CIRCUIT_TRIPPED_TIMEOUT_FACTOR_KEY, constant.DEFAULT_CIRCUIT_TRIPPED_TIMEOUT_FACTOR)), }}Copy the code
- NewDefaultHealthChecker instantiates DefaultHealthChecker
IsHealthy
Dubbo – go – v1.4.2 / cluster/router/healthcheck/default_health_check. Go
// IsHealthy evaluates the healthy state on the given Invoker based on the number of successive bad request
// and the current active request
func (c *DefaultHealthChecker) IsHealthy(invoker protocol.Invoker) bool {
urlStatus := protocol.GetURLStatus(invoker.GetUrl())
if c.isCircuitBreakerTripped(urlStatus) || urlStatus.GetActive() > c.GetOutStandingRequestConutLimit() {
logger.Debugf("Invoker [%s] is currently in circuitbreaker tripped state", invoker.GetUrl().Key())
return false
}
return true
}
Copy the code
- IsHealthy method by protocol. GetURLStatus (invoker. GetUrl ()) get urlStatus, after according to c.i sCircuitBreakerTripped (urlStatus) or
urlStatus.GetActive() > c.GetOutStandingRequestConutLimit()
Determine whether circuitbreaker tripped
isCircuitBreakerTripped
Dubbo – go – v1.4.2 / cluster/router/healthcheck/default_health_check. Go
// isCircuitBreakerTripped determine whether the invoker is in the tripped state by the number of successive bad request func (c *DefaultHealthChecker) isCircuitBreakerTripped(status *protocol.RPCStatus) bool { circuitBreakerTimeout := c.getCircuitBreakerTimeout(status) currentTime := protocol.CurrentTimeMillis() if circuitBreakerTimeout <= 0 { return false } return circuitBreakerTimeout > currentTime }Copy the code
- Be sad etCircuitBreakerTimeout chtistina georgina rossetti.british poetess isCircuitBreakerTripped method through get circuitBreakerTimeout (status), if circuitBreakerTimeout less than or equal to 0 returns false, Otherwise, check whether circuitBreakerTimeout is greater than currentTime
getCircuitBreakerTimeout
Dubbo – go – v1.4.2 / cluster/router/healthcheck/default_health_check. Go
// getCircuitBreakerTimeout get the timestamp recovered from tripped state, the unit is millisecond
func (c *DefaultHealthChecker) getCircuitBreakerTimeout(status *protocol.RPCStatus) int64 {
sleepWindow := c.getCircuitBreakerSleepWindowTime(status)
if sleepWindow <= 0 {
return 0
}
return status.GetLastRequestFailedTimestamp() + sleepWindow
}
Copy the code
- GetCircuitBreakerTimeout method to obtain sleepWindow, if sleepWindow less than or equal to zero, it returns 0. Otherwise returns the status GetLastRequestFailedTimestamp () + sleepWindow
getCircuitBreakerSleepWindowTime
Dubbo – go – v1.4.2 / cluster/router/healthcheck/default_health_check. Go
// getCircuitBreakerSleepWindowTime get the sleep window time of invoker, the unit is millisecond
func (c *DefaultHealthChecker) getCircuitBreakerSleepWindowTime(status *protocol.RPCStatus) int64 {
successiveFailureCount := status.GetSuccessiveRequestFailureCount()
diff := successiveFailureCount - c.GetRequestSuccessiveFailureThreshold()
if diff < 0 {
return 0
} else if diff > constant.DEFAULT_SUCCESSIVE_FAILED_REQUEST_MAX_DIFF {
diff = constant.DEFAULT_SUCCESSIVE_FAILED_REQUEST_MAX_DIFF
}
sleepWindow := (1 << diff) * c.GetCircuitTrippedTimeoutFactor()
if sleepWindow > constant.MAX_CIRCUIT_TRIPPED_TIMEOUT_IN_MS {
sleepWindow = constant.MAX_CIRCUIT_TRIPPED_TIMEOUT_IN_MS
}
return int64(sleepWindow)
}
Copy the code
- GetCircuitBreakerSleepWindowTime method by comparing the status. GetSuccessiveRequestFailureCount be sad etRequestSuccessiveFailureThreshold chtistina georgina rossetti.british poetess () and () Be sad etCircuitTrippedTimeoutFactor chtistina georgina rossetti.british poetess computing diff, then according to the calculation sleepWindow ()
summary
DefaultHealthChecker defines outStandingRequestConutLimit, requestSuccessiveFailureThreshold, circuitTrippedTimeoutFactor attributes; IsHealthy obtains urlStatus from protocol.geturlStatus (invoker.geturl ()). Then according to the c.i sCircuitBreakerTripped (urlStatus) or urlStatus. GetActive () > C.G etOutStandingRequestConutLimit () determine whether in the circuitbreaker tripped state
doc
- default_health_check