forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ResponseOps][task manager] log event loop delay for tasks when over …
…configured limit (elastic#126300) resolves elastic#124366 Adds new task manager configuration keys. - `xpack.task_manager.event_loop_delay.monitor` - whether to monitor event loop delay or not; added in case this specific monitoring causes other issues and we'd want to disable it. We don't know of any cases where we'd need this today - `xpack.task_manager.event_loop_delay.warn_threshold` - the number of milliseconds of event loop delay before logging a warning This code uses the `perf_hooks.monitorEventLoopDelay()` API[1] to collect the event loop delay while a task is running. [1] https://nodejs.org/api/perf_hooks.html#perf_hooksmonitoreventloopdelayoptions When a significant event loop delay is encountered, it's very likely that other tasks running at the same time will be affected, and so will also end up having a long event loop delay value, and warnings will be logged on those. Over time, though, tasks which have consistently long event loop delays will outnumber those unfortunate peer tasks, and be obvious from the volume in the logs. To make it a bit easier to find these when viewing Kibana logs in Discover, tags are added to the logged messages to make it easier to find them. One tag is `event-loop-blocked`, second is the task type, and the third is a string consisting of the task type and task id.
- Loading branch information
Showing
15 changed files
with
194 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { startTaskTimer, startTaskTimerWithEventLoopMonitoring } from './task_events'; | ||
|
||
const DelayIterations = 4; | ||
const DelayMillis = 250; | ||
const DelayTotal = DelayIterations * DelayMillis; | ||
|
||
async function nonBlockingDelay(millis: number) { | ||
await new Promise((resolve) => setTimeout(resolve, millis)); | ||
} | ||
|
||
async function blockingDelay(millis: number) { | ||
// get task in async queue | ||
await nonBlockingDelay(0); | ||
|
||
const end = Date.now() + millis; | ||
// eslint-disable-next-line no-empty | ||
while (Date.now() < end) {} | ||
} | ||
|
||
async function nonBlockingTask() { | ||
for (let i = 0; i < DelayIterations; i++) { | ||
await nonBlockingDelay(DelayMillis); | ||
} | ||
} | ||
|
||
async function blockingTask() { | ||
for (let i = 0; i < DelayIterations; i++) { | ||
await blockingDelay(DelayMillis); | ||
} | ||
} | ||
|
||
describe('task_events', () => { | ||
test('startTaskTimer', async () => { | ||
const stopTaskTimer = startTaskTimer(); | ||
await nonBlockingTask(); | ||
const result = stopTaskTimer(); | ||
expect(result.stop - result.start).not.toBeLessThan(DelayTotal); | ||
expect(result.eventLoopBlockMs).toBe(undefined); | ||
}); | ||
|
||
describe('startTaskTimerWithEventLoopMonitoring', () => { | ||
test('non-blocking', async () => { | ||
const stopTaskTimer = startTaskTimerWithEventLoopMonitoring({ | ||
monitor: true, | ||
warn_threshold: 5000, | ||
}); | ||
await nonBlockingTask(); | ||
const result = stopTaskTimer(); | ||
expect(result.stop - result.start).not.toBeLessThan(DelayTotal); | ||
expect(result.eventLoopBlockMs).toBeLessThan(DelayMillis); | ||
}); | ||
|
||
test('blocking', async () => { | ||
const stopTaskTimer = startTaskTimerWithEventLoopMonitoring({ | ||
monitor: true, | ||
warn_threshold: 5000, | ||
}); | ||
await blockingTask(); | ||
const result = stopTaskTimer(); | ||
expect(result.stop - result.start).not.toBeLessThan(DelayTotal); | ||
expect(result.eventLoopBlockMs).not.toBeLessThan(DelayMillis); | ||
}); | ||
|
||
test('not monitoring', async () => { | ||
const stopTaskTimer = startTaskTimerWithEventLoopMonitoring({ | ||
monitor: false, | ||
warn_threshold: 5000, | ||
}); | ||
await blockingTask(); | ||
const result = stopTaskTimer(); | ||
expect(result.stop - result.start).not.toBeLessThan(DelayTotal); | ||
expect(result.eventLoopBlockMs).toBe(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.