refactor(load-biaser): store penalty_secs as a u16#4550
Conversation
this commit is based upon #4537, but is written in part as preemptive review feedback related to #4546. in that change, we must remove the `Hash`, `PartialEq`, and `Eq` derivations on a number of types throughout the outbound proxy, making that change fairly involved. see, for example: 8675c7f this commit proposes an alteration to the load biaser crate that can avoid the need for these changes, both minimizing the size of the unified circuit breaker integration, and avoiding the risk of future changes introducing hashing or equality bugs should we add other fields to these structures in the future and neglect to update the manual `Hash` implementations. instead, we can change our model of the load biaser's config. by storing `penalty_secs` as an unsigned integer, this structure can now be compared and hashed. this value is then converted to a floating point f64 only at the site where we need to perform exponential weighted moving average arithmetic. finally, this also provides another benefit: by modeling our configuration in a way that makes illegal states (_negative penalty, NaN penalty_) impossible to represent, we no longer need to check for such states when constructing a load biasing layer. X-Ref: #4546 X-Ref: #4537 Signed-off-by: katelyn martin <kate@buoyant.io>
There was a problem hiding this comment.
That's interesting, although it loses precision that an operator might want to use, in case they precisely wanted 2.5 instead of 2 or 3. We could alternatively use a fixed point implementation, which would overcome the issue and allow Eq/Hash, at the cost of yet-another-dependency.
I'm inclined to say that it's probably ok to reduce the precision and reap the benefits. I'll revisit when working through the changes for biaser.
|
Hm, we could also store this as a Duration (impls Eq/Hash), or maybe as milliseconds (using u32). What do you think @cratelyn? |
i'm less inclined to pursue milliseconds seems like a reasonable choice though, and would align with the annotations proposed in linkerd/linkerd2#15317. |
just to confirm my understanding: fractional values like so if someone wanted a penalty of two-and-a-half seconds, they would write this as |
Yes, exactly, although at the parsing and validation layer we could do conversions as needed, the only requirement is that we're able to represent the expected values in the chosen type. |
this commit is based upon #4537, but is written in
part as preemptive review feedback related to #4546.
in that change, we must remove the
Hash,PartialEq, andEqderivations on a number of types throughout the outbound proxy, making
that change fairly involved.
see, for example: 8675c7f
this commit proposes an alteration to the load biaser crate that can
avoid the need for these changes, both minimizing the size of the
unified circuit breaker integration, and avoiding the risk of future
changes introducing hashing or equality bugs should we add other fields
to these structures in the future and neglect to update the manual
Hashimplementations.instead, we can change our model of the load biaser's config. by storing
penalty_secsas an unsigned integer, this structure can now becompared and hashed. this value is then converted to a floating point
f64 only at the site where we need to perform exponential weighted
moving average arithmetic.
finally, this also provides another benefit: by modeling our
configuration in a way that makes illegal states (negative penalty, NaN
penalty) impossible to represent, we no longer need to check for such
states when constructing a load biasing layer.
X-Ref: #4546
X-Ref: #4537
Signed-off-by: katelyn martin kate@buoyant.io