theme: geek-black
This is the third day of my participation in the August Text Challenge.More challenges in August
Configure service fuses and downgrades with Hystrix and the Hystris Dashboard
1. Hystrix profile
Hystrix provides services such as service downgrading, service fuses, and service limiting.
An avalanche
In microservice architectures, there are often multiple service layers called, and the failure of the underlying service may lead to cascading failures that make the entire system unusable, a phenomenon known as the service avalanche effect. Service avalanche effect is a process in which the unavailability of “service providers” leads to the unavailability of “service consumers” and gradually amplifies the unavailability.
demotion
When a request times out or resources are insufficient, service degradation is performed. Instead of invoking real service logic, fallback is used to directly return a support data to ensure the integrity of the service chain and avoid service avalanche.
fusing
When the number of Hystrix Command requests for back-end service failures exceeds a certain percentage (50% by default), the circuit breaker switches to the Open state (Open). All requests will fail and will not be sent to the back-end service. After the circuit breaker remains OPEN for a period of time (5 seconds by default), it automatically switches to half-open. The return of the next request is determined. If the request is successful, the breaker switches back to the CLOSED state, otherwise it switches back to the OPEN state.
Fuses directly sever the chain of requests, preventing system throughput from being affected by sending a large number of invalid requests, and the circuit breaker has the ability to detect and recover itself.
Fuses are typically configured at the service provider, while service degradation is used at the service consumer.
2.Hystrix
Create a project
3.Hystrix-dashboard
A panel for monitoring information
Create a project
Note: THE version of boot I’m using here is slightly lower 2.3.12
The new version of fuse is recommended to use Resilience4J,
Dashboard was introduced directly with version 2.5, so version 2.3 was used instead
use
The startup class adds an annotation @enablehystrixDashboard
Configure port 8400
Start the successful visit http://localhost:8400/hystrix
-
The first input field is the address of the microservice we want to monitor
-
The Delay parameter controls the Delay of polling monitoring information on the server. The default value is 2000 milliseconds. You can configure this parameter to reduce the network and CPU consumption of the client.
-
Title is the Title of monitoring information, which we generally fill in the micro service name
The consumer configures monitoring information
Add the dependency to the previously invoked service
<! -- Actuator Monitoring information -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Copy the code
Consumer configuration HystrixMetricsStreamServlet
You need to manually configure a servlet
package com.example.hystrix;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RestConfig {
@Bean
public ServletRegistrationBean getServlet(a) {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
returnregistrationBean; }}Copy the code
Dashboard configuration
#port
server:
port: 8400
#dashboard
hystrix:
dashboard:
proxy-stream-allow-list: "*"
Copy the code
Call the service to view the Dashboard
Dashboard complete path: http://localhost:8303/actuator/hystrix.stream
Invoke the service to view the monitoring