-
Notifications
You must be signed in to change notification settings - Fork 86
feat(circuitBreaker): configurable event loop delay percentile #1024
feat(circuitBreaker): configurable event loop delay percentile #1024
Conversation
Size Change: 0 B Total Size: 667 kB ℹ️ View Unchanged
|
src/server/utils/onModuleLoad.js
Outdated
@@ -129,6 +130,7 @@ export default function onModuleLoad({ | |||
setConfigureRequestLog(configureRequestLog); | |||
setCreateSsrFetch(createSsrFetch); | |||
setEventLoopDelayThreshold(eventLoopDelayThreshold); | |||
setEventLoopDelayPercentile(eventLoopDelayPercentile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want to avoid calling with undefined, the same goes for above
setEventLoopDelayPercentile(eventLoopDelayPercentile); | |
if(eventLoopDelayPercentile) { setEventLoopDelayPercentile(eventLoopDelayPercentile); } |
@@ -22,12 +22,24 @@ import { registerCircuitBreaker } from '../metrics/circuit-breaker'; | |||
|
|||
const { rootModuleName } = getServerStateConfig(); | |||
let eventLoopDelayThreshold = 250; | |||
let eventLoopDelayPercentile = 100; | |||
|
|||
export const setEventLoopDelayThreshold = (n) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe set to default when no value given
export const setEventLoopDelayThreshold = (n) => { | |
export const setEventLoopDelayThreshold = (n=eventLoopDelayThreshold) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not equivalent functionally as the current implementation will coerce a non-number into the default
if (process.env.NODE_ENV === 'development') return; | ||
// Return if root module is not loaded, as that is where threshold is configured | ||
if (!getModule(rootModuleName)) return; | ||
// Get event loop delay in milliseconds (from nanoseconds) | ||
const maxEventLoopDelay = eventLoopDelayHistogram.max / 1e6; | ||
const eventLoopDelay = eventLoopDelayHistogram.percentile(eventLoopDelayPercentile) / 1e6; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this handle any number ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just integers 1-100, as validated
}; | ||
|
||
export const setEventLoopDelayPercentile = (n) => { | ||
if (typeof n !== 'undefined' && (n !== Number.parseInt(n, 10) || n < 1 || n > 100)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just
if (!n && (n !== Number.parseInt(n, 10) || n < 1 || n > 100)) {
Description
New configuration option for circuit breakers event loop delay check
Motivation and Context
Currently the circuit breaker is based on max event loop delay, which is not ideal as it indicates an outlier rather than a trend. p(99) can be significantly lower than p(100) (max). The default is left at 100 to avoid a breaking change to behavior. This change required the addition of an interval upon which to reset the histogram since it biases lower over time.
How Has This Been Tested?
Unit test + running locally while monitoring circuit breaker metrics and load testing with autocanon
Types of Changes
Checklist:
a maintenancemain branch.What is the Impact to Developers Using One App?