简体   繁体   English

Resilience4j 断路器环形位缓冲区大小配置

[英]Resilience4j circuit-breaker ring bit buffer size configuration

I'm looking to implement resilience4j circuit breaking library into a web application.我希望将resilience4j断路库实现到Web 应用程序中。

My application talks to two services and each service receives anywhere between 20 and 150 requests per second depending on the time of day.我的应用程序与两个服务对话,每个服务每秒接收 20 到 150 个请求,具体取决于一天中的时间。 Resilience4j provides you with the ability to define a config for each circuit breaker which lets you configure the thresholds and ring buffer size. Resilience4j 为您提供了为每个断路器定义配置的能力,让您可以配置阈值和环形缓冲区大小。

Extra info on ring buffer size and resilience4j vs netflix hystrix implementation:关于环形缓冲区大小和弹性 4j 与 netflix hystrix 实现的额外信息:

Hystrix, by default, stores execution results in 10 1-second window buckets.默认情况下,Hystrix 将执行结果存储在 10 个 1 秒窗口桶中。 If a 1-second window bucket is passed, a new bucket is created and the oldest is dropped.如果传递了一个 1 秒的窗口桶,则会创建一个新的桶并丢弃最旧的桶。 This library stores execution results in Ring Bit Buffer without a statistical rolling time window.该库将执行结果存储在 Ring Bit Buffer 中,没有统计滚动时间窗口。 A successful call is stored as a 0 bit and a failed call is stored as a 1 bit.成功的呼叫存储为 0 位,失败的呼叫存储为 1 位。 The Ring Bit Buffer has a configurable fixed-size and stores the bits in a long[] array which is saving memory compared to a boolean array. Ring Bit Buffer 具有可配置的固定大小,并将位存储在 long[] 数组中,与布尔数组相比,它可以节省内存。 That means the Ring Bit Buffer only needs an array of 16 long (64-bit) values to store the status of 1024 calls.这意味着 Ring Bit Buffer 只需要一个包含 16 个长(64 位)值的数组来存储 1024 次调用的状态。 The advantage is that this CircuitBreaker works out-of-the-box for low and high frequency backend systems, because execution results are not dropped when a time window is passed.优点是这个 CircuitBreaker 对于低频和高频后端系统开箱即用,因为在经过一个时间窗口时不会丢弃执行结果。

My question is , with requests fluctuating between 20 and 150 per second, how do I determine the optimal size for the ring buffer?我的问题是,请求在每秒 20 到 150 之间波动,我如何确定环形缓冲区的最佳大小? How would I justify the number I've chosen if someone asked me this same question?如果有人问我同样的问题,我将如何证明我选择的数字是合理的?

If I set the ring buffer to 100, it will take 5 seconds to fill up @ 20 requests a second, and during peak hours it will take less than 1 second to fill up.如果我将环形缓冲区设置为 100,则每秒钟填满 20 个请求需要 5 秒,而在高峰时段填满需要不到 1 秒。 I'm not sure if I should be using a time based implementation like hystrix or if I can work around this with resilience4j.我不确定我是否应该使用像 hystrix 这样的基于时间的实现,或者我是否可以使用弹性 4j 来解决这个问题。

Completely agree with Jim Garrison on that one.完全同意 Jim Garrison 的观点。

This configuration will heavily depend on the requirements and behaviors of your application.此配置将在很大程度上取决于您的应用程序的要求和行为。 Before you can get an answer to your primary question在您得到主要问题的答案之前

With requests fluctuating between 20 and 150 per second, how do I determine the optimal size for the ring buffer?请求在每秒 20 到 150 之间波动,如何确定环形缓冲区的最佳大小?

you should decide what is the typical error rate for these particular requests that your system will treat like normal and the circuit will stay closed?您应该确定您的系统将正常处理并且电路保持关闭状态的这些特定请求的典型错误率是多少?

Also, you should take into account how fast your system should react to anomaly high error rates.此外,您应该考虑您的系统应对异常高错误率的反应速度。

By adjusting the CircuitBraker configuration you will actually balance between sensitivity and specificity and this balance completely depends on your business requirements.通过调整CircuitBraker配置,您实际上将在灵敏度和特异性之间取得平衡,而这种平衡完全取决于您的业务需求。 For example, if you have a system where safety and availability are top priorities you can accept some amount of false-positive circuit openings.例如,如果您的系统将安全性和可用性放在首位,您可以接受一定数量的误报电路开路。

In real production systems it is pretty hard to configure CircuitBreaker from scratch, so be ready to externalize this config and change it when needed.在实际生产系统中,从头开始配置 CircuitBreaker 非常困难,因此请准备好将此配置外部化并在需要时进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM