Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

Hystrix: why rollingStats.timeInMilliseconds is not taking effect?

This is an experimental setup I have done: rollingStats.timeInMilliseconds: 100 sleepWindowInMilliseconds: 200000 errorThresholdPercentage: 20 requestVolumeThreshold: 1

My intention was to create a scenario, where right after 1 failure it will go sleep window , so it will not execute run unless 200 seconds are over. But what I see is, it tries more than 3 seconds after the 1st failure, that means it kept calling run method. I must be wrong somehwere. Please give me some direction.

package com.test.mock;


import com.netflix.config.ConfigurationManager;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;

public class HystrixDemoCommand extends HystrixCommand<String> {

    public HystrixDemoCommand() throws Exception {
        
        super(HystrixCommandGroupKey.Factory.asKey("HystrixDemoCommandGroup"));
        HystrixCommandGroupKey.Factory.asKey("HystrixDemoCommandGroup");
        
        try {

            ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixDemoCommandGroup.execution.isolation.strategy", ExecutionIsolationStrategy.SEMAPHORE);
            ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixDemoCommandGroup.metrics.rollingStats.timeInMilliseconds", 100);

            ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixDemoCommandGroup.circuitBreaker.sleepWindowInMilliseconds", 200000);

            ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixDemoCommandGroup.circuitBreaker.errorThresholdPercentage", 20);

            ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixDemoCommandGroup.circuitBreaker.requestVolumeThreshold", 1);


            
        } catch (Exception exception) {
           throw new Exception("error initializing hystrix");

        }


    }

    @Override
    protected String run() throws Exception {
        /**client code starts here**/
        System.out.println("planning to execute run");
        Client client = Client.create();
        WebResource webresource = client.resource("https://a73c392-510a-4df3-9898-6e18dd2f773c.mock.pstmn.io/mockName");
        String responseStr = webresource.get(String.class);
        System.out.println("printing response:" + responseStr);
        return responseStr;
        /**client code ends here**/
    }

    protected String getFallback(){

        System.out.println("inside fallback");
        return "FALLBACK_0001";
        
    }
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...