Brief introduction
We discussed the Hystrix+feign+ribbon in the last section, but many people may know that Hystrix also have cable path isolation, signal isolation, and so on various parameters configuration, in these few records hystrix parameters,
First, Hystrix parameter use method
Through the annotations @hystrixcommand commandproperties to configure, the following is the Hystrix command timeout time command execution timeout, for 1000ms and do not enable timeout
@RestController Public classMoviecontroller {@AutowiredPrivateresttemplate resttemplate; @GetMapping ("/movie/{id}") @HystrixCommand (commandproperties={@HystrixProperty (name= "Execution.isolation.thread.timeoutInMilliseconds", value = "1000"), @HystrixProperty (name= "Execution.timeout.enabled", value = "false")},fallbackmethod = "Findbyidfallback") PublicUser FindByID (@PathVariable Long id) {return This. Resttemplate.getforobject ("http://microservice-provider-user/simple/" + ID, user.class); } /*** Fallback method *@paramID *@return */ Publicuser findbyidfallback (Long ID) {User user=NewUser (); User.setid (5L); returnuser; }}
Second, the Hystrix parameters are as follows
default Commandkey command in Hystrix.command.default and Hystrix.threadpool.default Propertiesexecution configuration of the related properties: Hystrix.command.default. Execution.isolation.strategy isolation policy, default is thread, optional thread|semaphore hystrix.command.default. Execution.isolation.thread.timeoutInMilliseconds command execution timeout, default 1000ms hystrix.command.defaultthe. Execution.timeout.enabled executes whether the timeout is enabled and Truehystrix.command is enabled by default.default. execution.isolation.thread.interruptOnTimeout occurs if the timeout is interrupted, the default Truehystrix.command.default. execution.isolation.semaphore.maxConcurrentRequests maximum number of concurrent requests, default 10, This parameter is valid when you use the Executionisolationstrategy.semaphore policy. If the maximum number of concurrent requests is reached, the request is rejected. The principle of choosing the semaphore size in theory is consistent with the choice of the thread size, but when semaphore is selected it is smaller and executes faster (MS level), or thread should be used. Semaphore should account for a small portion of the entire container (Tomcat) thread pool. Fallback related properties These parameters can be applied to the hystrix thread and Semaphore policy Hystrix.command.default. fallback.isolation.semaphore.maxConcurrentRequests if the number of concurrent numbers reaches this setting, the request is rejected and an exception is thrown and fallback is not invoked. Default 10hystrix.command.default. fallback.enabled if execution fails or if the request is denied, attempts to invoke Hystrixcommand.getfallback (). The default Truecircuit breaker related property Hystrix.command.defaultThe . Circuitbreaker.enabled is used to track the health of the circuit and to short-circuit the request if the nonconformance is not met. Default Truehystrix.command.default. Circuitbreaker.requestvolumethreshold the minimum number of requests within a rolling window. If set to 20, then when a rolling window time (say 1 rolling window is 10 seconds) received 19 requests, even if 19 requests failed, will not trigger circuit Break. Default 20hystrix.command.default. Circuitbreaker.sleepwindowinmilliseconds the time value that triggered the short-circuit, and when the value is set to 5000, the request is rejected within 5000 milliseconds after the trigger circuit break. The circuit is not closed until 5000 milliseconds. Default 5000hystrix.command.default. Circuitbreaker.errorthresholdpercentage error ratio threshold, if error rate >=This value, circuit will be opened and short-circuited all requests to trigger fallback. Default 50hystrix.command.default. Circuitbreaker.forceopen force open fuse, if this switch is turned on, then reject all request, default Falsehystrix.command.default. circuitbreaker.forceclosed force off Fuse If this switch is turned on, The circuit will remain closed and the Circuitbreaker.errorthresholdpercentagemetrics related parameters Hystrix.command ignored.default. metrics.rollingStats.timeInMilliseconds sets the time window value of the statistic, the millisecond value, circuit Breakwill be calculated based on the statistics of the 1 rolling window. If the rolling window is set to 10000 milliseconds, the rolling window is divided into n buckets, and each bucket contains statistics about the number of success,failure,timeout,rejection. Default 10000hystrix.command.default. Metrics.rollingStats.numBuckets set the number of rolling window to be divided, if numbuckets=10,rolling window=10000, then a bucket of time is 1 seconds. Must conform to rolling window% Numberbuckets = = 0. Default 10hystrix.command.defaultmetrics.rollingPercentile.enabled The calculation and tracking of the Enable indicator at execution time, the default Truehystrix.command.default. metrics.rollingPercentile.timeInMilliseconds set rolling percentile window time, default 60000hystrix.command.defaultthe. Metrics.rollingPercentile.numBuckets sets the numberbuckets of the rolling percentile window. Logic Ibid. Default 6hystrix.command.default. metrics.rollingPercentile.bucketSize if the bucket size=100, window=10s, if there are 500 executions in this 10s, only the last 100 executions will be counted into buckets. Increasing this value increases the memory overhead and the cost of sorting. Default 100hystrix.command.default. Metrics.healthSnapshot.intervalInMilliseconds record the interval between health snapshots (used to count success and error green), default 500msRequest Context Related parameters Hystrix.command.default. requestcache.enabled default True, you need to overload Getcachekey () and return NULL when Hystrix.command is not cached.default. requestlog.enabled log to Hystrixrequestlog, default true collapser Properties related parameters hystrix.collapser.default. Maxrequestsinbatch the maximum number of requests per batch, which triggers the batch, the default Integer.MAX_VALUEhystrix.collapser.default. Timerdelayinmilliseconds triggers the delay of the batch, or the time to create the batch + the value, the default 10hystrix.collapser.defaultThe . Requestcache.enabled is the cache for Hystrixcollapser.execute () and Hystrixcollapser.queue (), which is the default true ThreadPool Correlation parameter thread number The default value of 10 applies to most cases (which can sometimes be set to a smaller size), and if necessary, a basic formula can be follow:requests per second at peak time healthyx99th percentile Latency in seconds+some breathing rooms maximum supported requests per second (99% Average Response time +cache value) such as: 1000 requests per second can be processed,99%The request response time is 60ms, then the formula is: (0.060+0.012The basic principle is to keep the thread pool as small as possible, primarily to release stress and prevent resources from being blocked. When everything is normal, the thread pool typically has only 1 to 2 threads active to provide service Hystrix.threadpool.defaultthe maximum number of threads concurrently executed by the. Coresize, default 10hystrix.threadpool.defaultThe maximum number of queues for the. Maxqueuesize Blockingqueue, when set to-1, uses synchronousqueue with a positive value of linkedblcokingqueue. This setting is only valid at initialization time, after which you cannot modify the ThreadPool queue size unless reinitialising thread executor. Default-1. Hystrix.threadpool.default. queuesizerejectionthreshold even if Maxqueuesize is not reached, the request is rejected when the value is reached Queuesizerejectionthreshold. Since maxqueuesize cannot be dynamically modified, this parameter will allow us to set this value dynamically.ifMaxqueuesize = =-1, the field will not work Hystrix.threadpool.default. keepalivetimeminutes This setting is not valid if Corepoolsize and maxpoolsize are set to the same (default implementation). If you are using plugin (https://github.com/netflix/hystrix/wiki/plugins) using a custom implementation, this setting is used, default 1.Hystrix.threadpool.default. Metrics.rollingStats.timeInMilliseconds the time of the thread pool statistic indicator, default 10000hystrix.threadpool.default. metrics.rollingStats.numBuckets divides the rolling window into n buckets, the default 10
Source source technical support for complete projects 2147775633
Spring Cloud Spring Boot mybatis distributed microservices Cloud Architecture-hystrix parameter Details (eight)