go - golang 的 hystrix 库“电路打开”没有“超时”错误
问题描述
我们将 hystrix 用于我们的 golang 应用程序,在这里我们得到hystrix: circuit open错误,即使没有hystrix: timeout
hystrix 配置:
hystrix.ConfigureCommand(cmd, hystrix.CommandConfig{
Timeout: timeout,
MaxConcurrentRequests: 1000,
ErrorPercentThreshold: 5,
SleepWindow: 15 * 60 * 1000, //15 Minutes
})
在 hystrix 后备部分,我们记录错误消息信息。我们可以清楚地看到我们只有hystrix: circuit open error 没有任何其他错误
有时它的行为非常随机,在下图中我们可以看到hystrix: timeout和hystrix: circuit open之间没有相关性
sudo/示例 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
}
}
将其调整为大于默认值的某个数字修复了我的错误。
推荐阅读
- android - 如何在 androids GoogleSignIn 上获取刷新令牌?
- python - AttributeError:模块'pickle'在python中没有属性'load'
- python - Android 应用程序立即关闭。通过 buildozer p4a 编译
- python - 在特定匹配模式之后打印上面的 2 行(带有特定单词)
- java - 我需要提取我的 JScrollPane 的面板
- typescript - 在 Next.js 中使用“useSelector”、“useDispatch”钩子
- python - SQLAlchemy with_for_update 读取陈旧数据
- oracle-apex - Apex 自动备份
- javascript - jQuery:特定情况下“.hasClass()”函数的问题
- python - 在 tensorflow 2 中训练自定义多对一 RNN