Skip to content

Commit

Permalink
Make mget task claim strategy poll more frequently
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Aug 7, 2024
1 parent 358e104 commit f785202
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
12 changes: 11 additions & 1 deletion x-pack/plugins/task_manager/server/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { configSchema } from './config';
import { configSchema, CLAIM_STRATEGY_DEFAULT, CLAIM_STRATEGY_MGET } from './config';

describe('config validation', () => {
test('task manager defaults', () => {
Expand Down Expand Up @@ -245,4 +245,14 @@ describe('config validation', () => {
test('any claim strategy is valid', () => {
configSchema.validate({ claim_strategy: 'anything!' });
});

test('default claim strategy defaults poll interval to 3000ms', () => {
const result = configSchema.validate({ claim_strategy: CLAIM_STRATEGY_DEFAULT });
expect(result.poll_interval).toEqual(3000);
});

test('mget claim strategy defaults poll interval to 500ms', () => {
const result = configSchema.validate({ claim_strategy: CLAIM_STRATEGY_MGET });
expect(result.poll_interval).toEqual(500);
});
});
17 changes: 13 additions & 4 deletions x-pack/plugins/task_manager/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { schema, TypeOf } from '@kbn/config-schema';
export const MAX_WORKERS_LIMIT = 100;
export const DEFAULT_MAX_WORKERS = 10;
export const DEFAULT_POLL_INTERVAL = 3000;
export const MGET_DEFAULT_POLL_INTERVAL = 500;
export const DEFAULT_VERSION_CONFLICT_THRESHOLD = 80;
export const DEFAULT_MAX_EPHEMERAL_REQUEST_CAPACITY = MAX_WORKERS_LIMIT;

Expand Down Expand Up @@ -127,10 +128,18 @@ export const configSchema = schema.object(
default: taskExecutionFailureThresholdSchema,
}),
/* How often, in milliseconds, the task manager will look for more work. */
poll_interval: schema.number({
defaultValue: DEFAULT_POLL_INTERVAL,
min: 100,
}),
poll_interval: schema.conditional(
schema.siblingRef('claim_strategy'),
CLAIM_STRATEGY_MGET,
schema.number({
defaultValue: MGET_DEFAULT_POLL_INTERVAL,
min: 100,
}),
schema.number({
defaultValue: DEFAULT_POLL_INTERVAL,
min: 100,
})
),
/* How many requests can Task Manager buffer before it rejects new requests. */
request_capacity: schema.number({
// a nice round contrived number, feel free to change as we learn how it behaves
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/task_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class TaskManagerPlugin
this.nodeRoles = initContext.node.roles;
this.shouldRunBackgroundTasks = this.nodeRoles.backgroundTasks;
this.adHocTaskCounter = new AdHocTaskCounter();
console.log('*** POLL INTERVAL', this.config.poll_interval);
}

isNodeBackgroundTasksOnly() {
Expand Down

0 comments on commit f785202

Please sign in to comment.