Skip to content

Commit 0188943

Browse files
ymao1kibanamachine
authored andcommitted
Removing perf_hooks from task manager (elastic#117294)
1 parent 9349ed6 commit 0188943

File tree

4 files changed

+0
-48
lines changed

4 files changed

+0
-48
lines changed

x-pack/plugins/task_manager/server/lib/fill_pool.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* 2.0.
66
*/
77

8-
import { performance } from 'perf_hooks';
98
import { Observable } from 'rxjs';
109
import { concatMap, last } from 'rxjs/operators';
1110
import { ClaimOwnershipResult } from '../queries/task_claiming';
@@ -57,7 +56,6 @@ export async function fillPool(
5756
converter: (taskInstance: ConcreteTaskInstance) => TaskManagerRunner,
5857
run: (tasks: TaskManagerRunner[]) => Promise<TaskPoolRunResult>
5958
): Promise<TimedFillPoolResult> {
60-
performance.mark('fillPool.start');
6159
return new Promise((resolve, reject) => {
6260
const stopTaskTimer = startTaskTimer();
6361
const augmentTimingTo = (
@@ -76,12 +74,6 @@ export async function fillPool(
7674
res,
7775
async ({ docs, stats }) => {
7876
if (!docs.length) {
79-
performance.mark('fillPool.bailNoTasks');
80-
performance.measure(
81-
'fillPool.activityDurationUntilNoTasks',
82-
'fillPool.start',
83-
'fillPool.bailNoTasks'
84-
);
8577
return asOk({ result: TaskPoolRunResult.NoTaskWereRan, stats });
8678
}
8779
return asOk(
@@ -106,20 +98,12 @@ export async function fillPool(
10698
({ result, stats }) => {
10799
switch (result) {
108100
case TaskPoolRunResult.RanOutOfCapacity:
109-
performance.mark('fillPool.bailExhaustedCapacity');
110-
performance.measure(
111-
'fillPool.activityDurationUntilExhaustedCapacity',
112-
'fillPool.start',
113-
'fillPool.bailExhaustedCapacity'
114-
);
115101
return augmentTimingTo(FillPoolResult.RanOutOfCapacity, stats);
116102
case TaskPoolRunResult.RunningAtCapacity:
117-
performance.mark('fillPool.cycle');
118103
return augmentTimingTo(FillPoolResult.RunningAtCapacity, stats);
119104
case TaskPoolRunResult.NoTaskWereRan:
120105
return augmentTimingTo(FillPoolResult.NoTasksClaimed, stats);
121106
default:
122-
performance.mark('fillPool.cycle');
123107
return augmentTimingTo(FillPoolResult.PoolFilled, stats);
124108
}
125109
},

x-pack/plugins/task_manager/server/polling/task_poller.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* This module contains the logic for polling the task manager index for new work.
1010
*/
1111

12-
import { performance } from 'perf_hooks';
13-
import { after } from 'lodash';
1412
import { Subject, merge, of, Observable, combineLatest, timer } from 'rxjs';
1513
import { mapTo, filter, scan, concatMap, tap, catchError, switchMap } from 'rxjs/operators';
1614

@@ -113,7 +111,6 @@ export function createTaskPoller<T, H>({
113111
// take as many argumented calls as we have capacity for and call `work` with
114112
// those arguments. If the queue is empty this will still trigger work to be done
115113
concatMap(async (set: Set<T>) => {
116-
closeSleepPerf();
117114
return mapResult<H, Error, Result<H, PollingError<T>>>(
118115
await promiseResult<H, Error>(
119116
timeoutPromiseAfter<H, Error>(
@@ -126,7 +123,6 @@ export function createTaskPoller<T, H>({
126123
(err: Error) => asPollingError<T>(err, PollingErrorType.WorkError)
127124
);
128125
}),
129-
tap(openSleepPerf),
130126
// catch errors during polling for work
131127
catchError((err: Error) => of(asPollingError<T>(err, PollingErrorType.WorkError)))
132128
);
@@ -177,13 +173,3 @@ export class PollingError<T> extends Error {
177173
this.data = data;
178174
}
179175
}
180-
181-
const openSleepPerf = () => {
182-
performance.mark('TaskPoller.sleep');
183-
};
184-
// we only want to close after an open has been called, as we're counting the time *between* work cycles
185-
// so we'll ignore the first call to `closeSleepPerf` but we will run every subsequent call
186-
const closeSleepPerf = after(2, () => {
187-
performance.mark('TaskPoller.poll');
188-
performance.measure('TaskPoller.sleepDuration', 'TaskPoller.sleep', 'TaskPoller.poll');
189-
});

x-pack/plugins/task_manager/server/task_pool.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*/
1212
import { Observable, Subject } from 'rxjs';
1313
import moment, { Duration } from 'moment';
14-
import { performance } from 'perf_hooks';
1514
import { padStart } from 'lodash';
1615
import { Logger } from '../../../../src/core/server';
1716
import { TaskRunner } from './task_running';
@@ -111,7 +110,6 @@ export class TaskPool {
111110
public run = async (tasks: TaskRunner[]): Promise<TaskPoolRunResult> => {
112111
const [tasksToRun, leftOverTasks] = partitionListByCount(tasks, this.availableWorkers);
113112
if (tasksToRun.length) {
114-
performance.mark('attemptToRun_start');
115113
await Promise.all(
116114
tasksToRun
117115
.filter((taskRunner) => !this.tasksInPool.has(taskRunner.id))
@@ -130,9 +128,6 @@ export class TaskPool {
130128
.catch((err) => this.handleFailureOfMarkAsRunning(taskRunner, err));
131129
})
132130
);
133-
134-
performance.mark('attemptToRun_stop');
135-
performance.measure('taskPool.attemptToRun', 'attemptToRun_start', 'attemptToRun_stop');
136131
}
137132

138133
if (leftOverTasks.length) {

x-pack/plugins/task_manager/server/task_running/task_runner.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import apm from 'elastic-apm-node';
1515
import { withSpan } from '@kbn/apm-utils';
16-
import { performance } from 'perf_hooks';
1716
import { identity, defaults, flow } from 'lodash';
1817
import {
1918
Logger,
@@ -313,7 +312,6 @@ export class TaskManagerRunner implements TaskRunner {
313312
}`
314313
);
315314
}
316-
performance.mark('markTaskAsRunning_start');
317315

318316
const apmTrans = apm.startTransaction('taskManager', 'taskManager markTaskAsRunning');
319317

@@ -372,12 +370,10 @@ export class TaskManagerRunner implements TaskRunner {
372370
}
373371

374372
if (apmTrans) apmTrans.end('success');
375-
performanceStopMarkingTaskAsRunning();
376373
this.onTaskEvent(asTaskMarkRunningEvent(this.id, asOk(this.instance.task)));
377374
return true;
378375
} catch (error) {
379376
if (apmTrans) apmTrans.end('failure');
380-
performanceStopMarkingTaskAsRunning();
381377
this.onTaskEvent(asTaskMarkRunningEvent(this.id, asErr(error)));
382378
if (!SavedObjectsErrorHelpers.isConflictError(error)) {
383379
if (!SavedObjectsErrorHelpers.isNotFoundError(error)) {
@@ -617,15 +613,6 @@ function howManyMsUntilOwnershipClaimExpires(ownershipClaimedUntil: Date | null)
617613
return ownershipClaimedUntil ? ownershipClaimedUntil.getTime() - Date.now() : 0;
618614
}
619615

620-
function performanceStopMarkingTaskAsRunning() {
621-
performance.mark('markTaskAsRunning_stop');
622-
performance.measure(
623-
'taskRunner.markTaskAsRunning',
624-
'markTaskAsRunning_start',
625-
'markTaskAsRunning_stop'
626-
);
627-
}
628-
629616
// A type that extracts the Instance type out of TaskRunningStage
630617
// This helps us to better communicate to the developer what the expected "stage"
631618
// in a specific place in the code might be

0 commit comments

Comments
 (0)