断路器和连接超时有什么区别?
根据我的理解,断路器是一种在与其他服务通信时出现问题(比平时花费更长的时间)时可以“断开”连接的东西。它不会总是重试与损坏的服务进行通信,而是会等待一段时间,以便给损坏的服务时间来恢复。
但我们也已经有了“连接超时”,如果连接花费很长时间,它就会停止并返回错误。
那么有什么区别呢?
From my understanding, circuit breaker is a thing that can "disconnect" a connection when there is a issue (takes a long time than usual) when communicating to other service. Instead of always retrying to communicate with broken service, it will wait for a moment to give the broken service time to recover.
But we also already have "connection timeout", if a connection takes a long time it will stop and return error.
Therefore what is the difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这两个想法当然是相似的,并且可以用来实现相似的属性。
连接超时通常在较低级别实现。在你的问题中,你说“我们已经有了”。确实如此:大多数 TCP 或 HTTP 库默认提供此功能。了解某些服务不适用可能会有所帮助 - 例如 UDP 等无连接服务。
有时,即使连接成功,也可能出现问题。您连接的服务可能不断返回错误。或者,即使连接没有断开,也可能需要很长时间才能给出有用的答案。断路器模式可以捕获这些更高级别的方面。
我发现一些有用的参考:
The two ideas are certainly similar, and can be used to achieve similar properties.
A connection timeout is often implemented at a lower level. In your question, you say that "we already have" it. And it's true: most TCP or HTTP libraries will offer this feature by default. It might help to know that there are some services where it will not apply - for example connectionless services like UDP.
Sometimes, there can be a problem even if the connection is successful. It may be that the service you're connecting to keeps returning an error. Or maybe it takes a long time to respond with a useful answer, even though the connection doesn't drop. It's these higher-level aspects that can be caught with a circuit breaker pattern.
Some references that I find helpful: