go - golang的hystrix库“电路断开”而没有“超时”错误

标签 go hystrix netflix fault-tolerance

我们在golang应用程序中使用hystrix,在这里我们得到 hystrix:即使没有 hystrix,电路断开错误:超时

hystrix配置:

hystrix.ConfigureCommand(cmd, hystrix.CommandConfig{
        Timeout:               timeout,
        MaxConcurrentRequests: 1000,
        ErrorPercentThreshold: 5,
        SleepWindow:           15 * 60 * 1000, //15 Minutes
    })

在hystrix后备部分中,我们记录错误消息信息。我们可以清楚地看到我们只有 hystrix:电路断开错误,没有任何其他错误

irregular circuit open

有时它的行为非常随机,在下图中,我们可以看到 hystrix:超时 hystrix之间没有相关性:电路断开

no relation b/w circuit open and timeout

sudo / sample hystrix代码:
func crawl(vendor string, req *http.Request, timeout int) (result []byte) {

    hystrix.Do(vendor, func() error {

        resp, err := httpClient.Do(req)
        if err != nil {
            log.Errorln("Error sending post request: ", err)
        } else {
            defer resp.Body.Close()
        }
        respBody, errResp := ioutil.ReadAll(resp.Body)
        if errResp != nil {
            log.WithFields(log.Fields{"RequestID": requestID}).Errorln("Error reading parser response", errResp, resp.Status)
        }

        if resp.StatusCode == 200 {
            result = respBody
        } else {
            log.Errorln(" SERVER SIDE ERROR", resp.StatusCode, obj)
        }

        return nil
    }, func(err error) error {
        logApiTimeouts(vendor, err)
        log.WithFields(log.Fields{"RequestID": requestID}).Errorln("Hystrix Error:", err, obj)
        return nil
    })
}

有没有人遇到此错误,以及如何解决?

最佳答案

可能是因为requestVolumeThreshold的默认设置为20。
根据hystrix golang客户端的文档,

// DefaultVolumeThreshold is the minimum number of requests needed before a circuit can be tripped due to health
DefaultVolumeThreshold = 20
你可以用
// Settings returns the hystrix command config
func (c Config) Settings() hystrix.CommandConfig {
   return hystrix.CommandConfig{
      Timeout:                8000,
      RequestVolumeThreshold: 1000, // FIXME: all calls must be paginated
   }
}
将其调整为大于默认值的某个数字可修复我的错误。

关于go - golang的hystrix库“电路断开”而没有“超时”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59435420/

相关文章:

function - 尝试取消引用一个接口(interface),该接口(interface)是指向后端结构对象的指针,因此我可以按值传递给函数

go - 为什么 atomic.StoreUint32 优于 sync.Once 中的正常分配?

go - 如何生成struct lowerCamelCase json标签

spring-cloud - Spring Cloud 断路器或 Hystrix

spring-boot - 使用 Spring Boot 和 Netflix Zuul 的简单反向代理

java - 从 WAR/JAR 文件安装 Hysterix 涡轮机

go - 将方法转换为 func var

java - Spring Hystrix 未在内部方法上触发

high-availability - Hystrix命令关键决定,服务名称+实例IP+Api名称?

java - Netflix Karyon 不使用 Governator 创建资源类