Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

feat(circuitBreaker): configurable event loop delay percentile #1024

Merged
merged 3 commits into from
Jun 19, 2023

Conversation

10xLaCroixDrinker
Copy link
Member

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)
  • Dependency update
  • Security update

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • These changes should be applied to a maintenance main branch.
  • This change requires cross browser checks.
  • Performance tests should be ran against the server prior to merging.
  • This change impacts caching for client browsers.
  • This change impacts HTTP headers.
  • This change adds additional environment variable requirements for One App users.
  • I have added the Apache 2.0 license header to any new files created.

What is the Impact to Developers Using One App?

@github-actions
Copy link
Contributor

github-actions bot commented Jun 15, 2023

Size Change: 0 B

Total Size: 667 kB

ℹ️ View Unchanged
Filename Size
./build/app/app.js 161 kB
./build/app/app~vendors.js 377 kB
./build/app/runtime.js 7.07 kB
./build/app/service-worker-client.js 7.26 kB
./build/app/vendors.js 114 kB

compressed-size-action

@@ -129,6 +130,7 @@ export default function onModuleLoad({
setConfigureRequestLog(configureRequestLog);
setCreateSsrFetch(createSsrFetch);
setEventLoopDelayThreshold(eventLoopDelayThreshold);
setEventLoopDelayPercentile(eventLoopDelayPercentile);
Copy link
Contributor

@JAdshead JAdshead Jun 15, 2023

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

Suggested change
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) => {
Copy link
Contributor

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

Suggested change
export const setEventLoopDelayThreshold = (n) => {
export const setEventLoopDelayThreshold = (n=eventLoopDelayThreshold) => {

Copy link
Member Author

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;
Copy link
Contributor

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 ?

Copy link
Member Author

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)) {
Copy link
Contributor

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)) {

@JAdshead JAdshead merged commit b161652 into 5.x.x Jun 19, 2023
@JAdshead JAdshead deleted the feature/configurable-event-loop-delay-threshold branch June 19, 2023 16:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants